Presupuestador_web/client/src/Routes.tsx

71 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-06-06 11:05:54 +00:00
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import { ProtectedRoute } from "./components";
2024-06-06 21:07:40 +00:00
import { DashboardPage, LogoutPage } from "./pages";
2024-06-06 11:05:54 +00:00
import { LoginPage } from "./pages/LoginPage";
export const Routes = () => {
// Define public routes accessible to all users
const routesForPublic = [
{
path: "/service",
element: <div>Service Page</div>,
},
{
path: "/about-us",
element: <div>About Us</div>,
},
];
// Define routes accessible only to authenticated users
const routesForAuthenticatedOnly = [
2024-06-06 21:07:40 +00:00
{
path: "/profile",
element: (
<ProtectedRoute>
<h1>Profile</h1>
</ProtectedRoute>
),
},
{
path: "/logout",
element: (
<ProtectedRoute>
<LogoutPage />
</ProtectedRoute>
),
},
2024-06-06 11:05:54 +00:00
{
path: "/admin",
element: <ProtectedRoute />, // Wrap the component in ProtectedRoute
children: [
{
path: "",
element: <div>Dashboard</div>,
},
],
},
];
// Define routes accessible only to non-authenticated users
const routesForNotAuthenticatedOnly = [
{
path: "/",
2024-06-06 21:07:40 +00:00
Component: DashboardPage,
2024-06-06 11:05:54 +00:00
},
{
path: "/login",
Component: LoginPage,
},
];
// Combine and conditionally include routes based on authentication status
const router = createBrowserRouter([
...routesForPublic,
2024-06-06 21:07:40 +00:00
...routesForNotAuthenticatedOnly,
2024-06-06 11:05:54 +00:00
...routesForAuthenticatedOnly,
]);
// Provide the router configuration using RouterProvider
return <RouterProvider router={router} />;
};