import { Fragment, type ComponentType } from "react"; import type { RouteObject } from "react-router"; import { generateModalRoutes, generatePreservedRoutes, generateRegularRoutes, } from "@generouted/react-router/core"; import { MODALS, PRESERVED, ROUTES } from "@/routing/glob-imports"; import { remapAppToPages } from "@/routing/remap-routes"; import { createLazyRoute, type RouteModule } from "@/routing/route-module"; import { createAppShellRoute } from "@/routing/app-shell"; const preservedRoutes = generatePreservedRoutes(remapAppToPages(PRESERVED)); const modalRoutes = generateModalRoutes(remapAppToPages(MODALS)) as Record; const regularRoutes = generateRegularRoutes(remapAppToPages(ROUTES), (moduleLoader, key) => createLazyRoute(moduleLoader as () => Promise, key), ); const appLayout = preservedRoutes?.["_app"] as RouteModule | undefined; const notFound = preservedRoutes?.["404"] as RouteModule | undefined; const appShell = createAppShellRoute(appLayout, modalRoutes); const fallback: RouteObject = { path: "*", Component: notFound?.default ?? Fragment }; export const routes: RouteObject[] = [{ ...appShell, children: [...regularRoutes, fallback] }];