import { Loader } from "@mantine/core"; import { lazy, Suspense } from "react"; import { Navigate, Route, Routes, useLocation } from "react-router"; import { useAuth } from "@/features/auth"; const AccountPage = lazy(async () => { const { AccountPage } = await import("@/pages/account"); return { default: AccountPage }; }); const AccountEventsPage = lazy(async () => { const { AccountEventsPage } = await import("@/pages/account-events"); return { default: AccountEventsPage }; }); const AccountOperationsPage = lazy(async () => { const { AccountOperationsPage } = await import("@/pages/account-operations"); return { default: AccountOperationsPage }; }); const AccountsPage = lazy(async () => { const { AccountsPage } = await import("@/pages/accounts"); return { default: AccountsPage }; }); const LoginPage = lazy(async () => { const { LoginPage } = await import("@/pages/login"); return { default: LoginPage }; }); const NotFoundPage = lazy(async () => { const { NotFoundPage } = await import("@/pages/not-found"); return { default: NotFoundPage }; }); const RegisterPage = lazy(async () => { const { RegisterPage } = await import("@/pages/register"); return { default: RegisterPage }; }); const SettingsPage = lazy(async () => { const { SettingsPage } = await import("@/pages/settings"); return { default: SettingsPage }; }); const ProtectedLayout = lazy(async () => { const { ProtectedLayout } = await import("./ProtectedLayout"); return { default: ProtectedLayout }; }); function LazyPage({ children }: { children: React.ReactNode }) { return }>{children}; } function Protected({ children }: { children: React.ReactNode }) { const { user, ready } = useAuth(); const location = useLocation(); if (!ready) return null; return user ? ( children ) : ( ); } function Public({ children }: { children: React.ReactNode }) { const { user, ready } = useAuth(); if (!ready) return null; return user ? : children; } export function AppRoutes() { return ( } /> } /> } /> } > } /> } /> } /> } /> } /> } /> ); }