Presupuestador_web/client/src/Routes.tsx

72 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-06-06 11:05:54 +00:00
import { RouterProvider, createBrowserRouter } from "react-router-dom";
2024-06-09 20:04:46 +00:00
import { LoginPage, LogoutPage, StartPage } from "./app";
import { CatalogList } from "./app/catalog";
import { DashboardPage } from "./app/dashboard";
2024-06-06 11:05:54 +00:00
import { ProtectedRoute } from "./components";
export const Routes = () => {
// Define public routes accessible to all users
const routesForPublic = [
{
2024-06-09 20:04:46 +00:00
path: "/",
Component: StartPage,
2024-06-06 11:05:54 +00:00
},
];
// Define routes accessible only to authenticated users
const routesForAuthenticatedOnly = [
2024-06-09 20:04:46 +00:00
{
path: "/home",
Component: DashboardPage,
},
{
path: "/catalog",
Component: CatalogList,
},
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: "/login",
Component: LoginPage,
},
];
// Combine and conditionally include routes based on authentication status
const router = createBrowserRouter([
...routesForPublic,
...routesForAuthenticatedOnly,
2024-06-09 20:04:46 +00:00
...routesForNotAuthenticatedOnly,
2024-06-06 11:05:54 +00:00
]);
// Provide the router configuration using RouterProvider
return <RouterProvider router={router} />;
};