blob: a7a04190b21c359956cd17cc82dabdfa5ab016a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
|