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