You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.5KB

  1. import { PageID } from "pages";
  2. import LoadingScreen from "components/LoadingScreen";
  3. import useAuth from "hooks/useAuth";
  4. import SimpleLayout from "layouts/simple";
  5. import { ElementType, Suspense, lazy, useMemo } from "react";
  6. import { RouteObject, useRoutes } from "react-router-dom";
  7. import { getRoute } from "./path";
  8. import DashboardRoutes from "./sub/dashboard";
  9. export const Loadable = (Component: ElementType) => (props: any) => {
  10. return (
  11. <Suspense fallback={<LoadingScreen />}>
  12. <Component {...props} />
  13. </Suspense>
  14. );
  15. };
  16. const CommonRoutes = (): RouteObject => ({
  17. element: <SimpleLayout />,
  18. children: [{}],
  19. });
  20. const AuthRoutes = (): RouteObject => ({
  21. element: <SimpleLayout />,
  22. children: [
  23. {
  24. path: getRoute(PageID.LOGIN),
  25. element: <Login />,
  26. },
  27. {
  28. path: getRoute(PageID.LOGOUT),
  29. element: <Logout />,
  30. },
  31. {},
  32. ],
  33. });
  34. export function Routes() {
  35. const { initialized } = useAuth();
  36. return useRoutes([
  37. CommonRoutes(),
  38. AuthRoutes(),
  39. ...DashboardRoutes(),
  40. {
  41. path: "403",
  42. element: <Page403 />,
  43. },
  44. {
  45. path: "*",
  46. element: initialized ? <Page404 /> : <LoadingScreen />,
  47. },
  48. ]);
  49. }
  50. // 認証関連 -------------------------------
  51. const Login = Loadable(lazy(() => import("pages/auth/login")));
  52. const Logout = Loadable(lazy(() => import("pages/auth/logout")));
  53. // その他 ---------------------------------
  54. const Page403 = Loadable(lazy(() => import("pages/common/Page403")));
  55. const Page404 = Loadable(lazy(() => import("pages/common/Page404")));