import { lazy } from "react"; import { createBrowserRouter } from "react-router-dom"; import App from "@/App"; import { initialGlobalState } from "@/store/module"; const Root = lazy(() => import("@/layouts/Root")); const SignIn = lazy(() => import("@/pages/SignIn")); const SignUp = lazy(() => import("@/pages/SignUp")); const AuthCallback = lazy(() => import("@/pages/AuthCallback")); const Explore = lazy(() => import("@/pages/Explore")); const Home = lazy(() => import("@/pages/Home")); const UserProfile = lazy(() => import("@/pages/UserProfile")); const MemoDetail = lazy(() => import("@/pages/MemoDetail")); const EmbedMemo = lazy(() => import("@/pages/EmbedMemo")); const Archived = lazy(() => import("@/pages/Archived")); const DailyReview = lazy(() => import("@/pages/DailyReview")); const Resources = lazy(() => import("@/pages/Resources")); const Inboxes = lazy(() => import("@/pages/Inboxes")); const Setting = lazy(() => import("@/pages/Setting")); const NotFound = lazy(() => import("@/pages/NotFound")); const initialGlobalStateLoader = async () => { try { await initialGlobalState(); } catch (error) { // do nothing. } return null; }; const router = createBrowserRouter([ { path: "/", element: , loader: () => initialGlobalStateLoader(), children: [ { path: "/auth", element: , }, { path: "/auth/signup", element: , }, { path: "/auth/callback", element: , }, { path: "/", element: , children: [ { path: "", element: , }, { path: "review", element: , }, { path: "resources", element: , }, { path: "inbox", element: , }, { path: "archived", element: , }, { path: "setting", element: , }, { path: "explore", element: , }, ], }, { path: "/m/:memoId", element: , }, { path: "/m/:memoId/embed", element: , }, { path: "/u/:username", element: , }, { path: "*", element: , }, ], }, ]); export default router;