aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/router.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/router.tsx')
-rw-r--r--src/router.tsx28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/router.tsx b/src/router.tsx
new file mode 100644
index 0000000..a7a0419
--- /dev/null
+++ b/src/router.tsx
@@ -0,0 +1,28 @@
+import {
+ createBrowserRouter,
+ createHashRouter,
+ type RouteObject,
+} from 'react-router-dom'
+import { appConfig } from '../app.config'
+import { appRoutes } from './app-routes'
+import { AppLayout } from './components/AppLayout'
+import { NotFoundPage } from './pages/NotFoundPage'
+
+const pageRoutes: RouteObject[] = appRoutes.map((route) =>
+ route.path === '/'
+ ? { index: true, element: route.element }
+ : { path: route.path.slice(1), element: route.element },
+)
+
+const routes: RouteObject[] = [
+ {
+ path: '/',
+ element: <AppLayout />,
+ children: [...pageRoutes, { path: '*', element: <NotFoundPage /> }],
+ },
+]
+
+export const router =
+ appConfig.routerMode === 'hash'
+ ? createHashRouter(routes)
+ : createBrowserRouter(routes)