import type { ComponentType } from "react"; import { lazy, Suspense } from "react"; import { createBrowserRouter } from "react-router-dom"; import App from "@/App"; import Spinner from "@/components/Spinner"; import MainLayout from "@/layouts/MainLayout"; import RootLayout from "@/layouts/RootLayout"; import Home from "@/pages/Home"; const AdminSignIn = lazy(() => import("@/pages/AdminSignIn")); const Archived = lazy(() => import("@/pages/Archived")); const AuthCallback = lazy(() => import("@/pages/AuthCallback")); const Explore = lazy(() => import("@/pages/Explore")); const Inboxes = lazy(() => import("@/pages/Inboxes")); const MemoDetail = lazy(() => import("@/pages/MemoDetail")); const NotFound = lazy(() => import("@/pages/NotFound")); const PermissionDenied = lazy(() => import("@/pages/PermissionDenied")); const Attachments = lazy(() => import("@/pages/Attachments")); const Setting = lazy(() => import("@/pages/Setting")); const SignIn = lazy(() => import("@/pages/SignIn")); const SignUp = lazy(() => import("@/pages/SignUp")); const UserProfile = lazy(() => import("@/pages/UserProfile")); const MemoDetailRedirect = lazy(() => import("./MemoDetailRedirect")); import { ROUTES } from "./routes"; // Backward compatibility alias export const Routes = ROUTES; export { ROUTES }; // Helper component to reduce Suspense boilerplate for lazy routes const LazyRoute = ({ component: Component }: { component: ComponentType }) => ( } > ); const router = createBrowserRouter([ { path: "/", element: , children: [ { path: Routes.AUTH, children: [ { path: "", element: }, { path: "admin", element: }, { path: "signup", element: }, { path: "callback", element: }, ], }, { path: Routes.ROOT, element: , children: [ { element: , children: [ { path: "", element: }, { path: Routes.EXPLORE, element: }, { path: Routes.ARCHIVED, element: }, { path: "u/:username", element: }, ], }, { path: Routes.ATTACHMENTS, element: }, { path: Routes.INBOX, element: }, { path: Routes.SETTING, element: }, { path: "memos/:uid", element: }, // Redirect old path to new path { path: "m/:uid", element: }, { path: "403", element: }, { path: "404", element: }, { path: "*", element: }, ], }, ], }, ]); export default router;