-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
BrowserRouter
to RouterProvider
for hpc-cdm
https://reactrouter.com/6.28.0/components/routes#routes In `hpc-cdm` there are many `<Routes />` elements, for the way is built it makes sense to let these `<Routes />` where they are instead of briging all of them to `main.tsx` since we have logic inside these `<Routes />`. In documentation they say that from `v6` and on, it is an 'uncommon practice', but for the way this was thought out, it would need a major rewrite or to let as it is for readability and maintenence ease purpose.
- Loading branch information
Showing
3 changed files
with
81 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { BrowserRouter } from 'react-router'; | ||
import { createBrowserRouter, Navigate, RouterProvider } from 'react-router'; | ||
import { ThemeProvider } from '@unocha/hpc-ui'; | ||
|
||
import App from './app/app'; | ||
import './assets/styles/enketo.css'; | ||
import { RouteParamsValidator } from './app/components/route-params-validator'; | ||
import * as paths from './app/paths'; | ||
|
||
import PageAdmin from './app/pages/admin'; | ||
import PageNotFound from './app/pages/not-found'; | ||
import PageOperationsList from './app/pages/operations-list'; | ||
import PageOperation from './app/pages/operation'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
if (!rootElement) { | ||
throw new Error('Failed to find the root element'); | ||
} | ||
const root = ReactDOM.createRoot(rootElement); | ||
|
||
root.render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<App /> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
const router = createBrowserRouter([ | ||
{ | ||
path: paths.home(), | ||
element: ( | ||
<ThemeProvider> | ||
<App /> | ||
</ThemeProvider> | ||
), | ||
children: [ | ||
{ path: paths.home(), element: <Navigate to={paths.operations()} /> }, | ||
{ path: paths.operations(), element: <PageOperationsList /> }, | ||
{ | ||
path: paths.operationRoot(), | ||
element: ( | ||
<RouteParamsValidator element={<PageOperation />} routeParam="id" /> | ||
), | ||
}, | ||
{ | ||
path: paths.adminRoot(), | ||
element: <PageAdmin />, | ||
}, | ||
{ path: paths.root(), element: <PageNotFound /> }, | ||
], | ||
}, | ||
]); | ||
|
||
root.render(<RouterProvider router={router} />); |