import type { ComponentType, ReactNode } from "react" import { createBrowserRouter, Navigate } from "react-router-dom" import ErrorPage from "@/components/ErrorPage" import Layout from "@/components/Layout" import EmptyLayout from "@/components/EmptyLayout" import { isAuthenticated } from "@/store/auth-slice" import { useAppSelector } from "@/store" function lazy }>(importer: () => Promise) { return async () => { const module = await importer() return { Component: module.default } } } const hydrateFallbackElement =
Loading...
function RequireAuth({ children }: { children: ReactNode }) { const authenticated = useAppSelector(isAuthenticated) if (!authenticated) return return <>{children} } const router = createBrowserRouter( [ { path: "/", element: , }, { element: ( ), hydrateFallbackElement, errorElement: , children: [ { path: "dashboard", lazy: lazy(() => import("@/pages/Dashboard")), }, { path: "artefacts", lazy: lazy(() => import("@/pages/Artefacts")), }, { path: "deployments", lazy: lazy(() => import("@/pages/Deployments")), }, { path: "users", lazy: lazy(() => import("@/pages/Users")), }, ], }, { element: , hydrateFallbackElement, errorElement: , children: [ { path: "login", lazy: lazy(() => import("@/pages/Login")), }, ], }, ], { basename: "/" } ) export default router