|
1 | 1 | import { |
2 | 2 | createBrowserRouter, |
3 | | - RouterProvider |
4 | | -} from "react-router" |
| 3 | + type RouteObject, |
| 4 | + RouterProvider, |
| 5 | +} from 'react-router'; |
| 6 | +import mapboxgl from 'mapbox-gl'; |
5 | 7 |
|
6 | | -import type { RouteConfig } from "#root/config/routes.ts"; |
7 | | -import routes from "#root/config/routes.ts"; |
8 | | -import PageError from "#views/PageError/index.tsx"; |
| 8 | +import { mapboxToken } from '#config'; |
| 9 | +import type { RouteConfig } from '#root/config/routes.ts'; |
| 10 | +import routes from '#root/config/routes.ts'; |
| 11 | +import PageError from '#views/PageError/index.tsx'; |
9 | 12 |
|
10 | 13 | const privateRoutes = Object.values(routes).filter( |
11 | | - ({ visibility }) => visibility === "is-authenticated", |
| 14 | + ({ visibility }) => visibility === 'is-authenticated', |
12 | 15 | ); |
13 | 16 |
|
14 | 17 | const publicRoutes = Object.values(routes).filter( |
15 | | - ({ visibility }) => visibility === "is-anything", |
| 18 | + ({ visibility }) => visibility === 'is-anything', |
16 | 19 | ); |
17 | 20 |
|
18 | 21 | const guestRoutes = Object.values(routes).filter( |
19 | | - ({ visibility }) => visibility === "is-not-authenticated", |
| 22 | + ({ visibility }) => visibility === 'is-not-authenticated', |
20 | 23 | ); |
21 | 24 |
|
22 | | -function mapRoute(routeConfig: RouteConfig) { |
| 25 | +function mapRoute(routeConfig: RouteConfig): RouteObject { |
| 26 | + // Only truly index routes: no path, index: true |
| 27 | + if (routeConfig.index && !routeConfig.path) { |
| 28 | + return { |
| 29 | + index: true, |
| 30 | + lazy: async () => { |
| 31 | + const { default: Component } = await routeConfig.load(); |
| 32 | + return { Component }; |
| 33 | + }, |
| 34 | + }; |
| 35 | + } |
| 36 | + |
23 | 37 | return { |
24 | | - index: routeConfig.index, |
25 | 38 | path: routeConfig.path, |
26 | 39 | lazy: async () => { |
27 | 40 | const { default: Component } = await routeConfig.load(); |
28 | 41 | return { Component }; |
29 | 42 | }, |
| 43 | + children: routeConfig.children?.map(mapRoute), |
30 | 44 | }; |
31 | 45 | } |
32 | 46 |
|
| 47 | +mapboxgl.accessToken = mapboxToken ?? ''; |
| 48 | +mapboxgl.setRTLTextPlugin( |
| 49 | + 'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js', |
| 50 | + // eslint-disable-next-line no-console |
| 51 | + (err) => { console.error(err); }, |
| 52 | + true, |
| 53 | +); |
| 54 | + |
33 | 55 | const router = createBrowserRouter([ |
34 | 56 | { |
35 | 57 | errorElement: <PageError />, |
36 | 58 | lazy: async () => { |
37 | | - const { default: Component } = await import("./Root/index.tsx"); |
| 59 | + const { default: Component } = await import('./Root/index.tsx'); |
38 | 60 | return { Component }; |
39 | 61 | }, |
40 | 62 | children: [ |
41 | 63 | { |
42 | 64 | lazy: async () => { |
43 | | - const { default: Component } = |
44 | | - await import("./views/RootLayout/index.tsx"); |
| 65 | + const { default: Component } = await import('./views/RootLayout/index.tsx'); |
45 | 66 | return { Component }; |
46 | 67 | }, |
47 | 68 | children: [ |
48 | 69 | { |
49 | 70 | lazy: async () => { |
50 | | - const { default: Component } = |
51 | | - await import("./views/GuestLayout/index.tsx"); |
| 71 | + const { default: Component } = await import('./views/GuestLayout/index.tsx'); |
52 | 72 | return { Component }; |
53 | 73 | }, |
54 | 74 | children: guestRoutes.map(mapRoute), |
55 | 75 | }, |
56 | 76 | { |
57 | 77 | lazy: async () => { |
58 | | - const { default: Component } = |
59 | | - await import("./views/PrivateLayout/index.tsx"); |
| 78 | + const { default: Component } = await import('./views/PrivateLayout/index.tsx'); |
60 | 79 | return { Component }; |
61 | 80 | }, |
62 | 81 | children: privateRoutes.map(mapRoute), |
63 | 82 | }, |
64 | 83 | { |
65 | 84 | lazy: async () => { |
66 | | - const { default: Component } = |
67 | | - await import("./views/PublicLayout/index.tsx"); |
| 85 | + const { default: Component } = await import('./views/PublicLayout/index.tsx'); |
68 | 86 | return { Component }; |
69 | 87 | }, |
70 | 88 | children: publicRoutes.map(mapRoute), |
|
0 commit comments