2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

[P UI] Router syntax switch (#5575)

* switched routes syntax

* switched to nested routes
This commit is contained in:
Matthias Mair 2023-09-20 00:51:50 -04:00 committed by GitHub
parent c6075a2064
commit 6c5b9e0108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 100 deletions

View File

@ -1,5 +1,5 @@
import { lazy } from 'react'; import { lazy } from 'react';
import { createBrowserRouter } from 'react-router-dom'; import { Route, Routes } from 'react-router-dom';
import { Loadable } from './functions/loading'; import { Loadable } from './functions/loading';
@ -58,100 +58,37 @@ export const Set_Password = Loadable(
); );
// Routes // Routes
export const router = createBrowserRouter( export const routes = (
[ <Routes>
{ <Route path="*" element={<NotFound />} errorElement={<ErrorPage />} />
path: '*', <Route path="/" element={<LayoutComponent />} errorElement={<ErrorPage />}>
element: <NotFound />, <Route index element={<Home />} />,
errorElement: <ErrorPage /> <Route path="home/" element={<Home />} />,
}, <Route path="dashboard/" element={<Dashboard />} />,
{ <Route path="notifications/" element={<Notifications />} />,
path: '/', <Route path="playground/" element={<Playground />} />,
element: <LayoutComponent />, <Route path="scan/" element={<Scan />} />,
errorElement: <ErrorPage />, <Route path="part/">
children: [ <Route index element={<CategoryDetail />} />
{ <Route path="category/:id" element={<CategoryDetail />} />
index: true, <Route path=":id/" element={<PartDetail />} />
element: <Home /> </Route>
}, <Route path="stock/">
{ <Route index element={<LocationDetail />} />
path: 'home/', <Route path="location/:id" element={<LocationDetail />} />
element: <Home /> <Route path="item/:id/" element={<StockDetail />} />
}, </Route>
{ <Route path="build/">
path: 'dashboard/', <Route index element={<BuildIndex />} />
element: <Dashboard /> <Route path=":id/" element={<BuildDetail />} />
}, </Route>
{ <Route path="/profile/:tabValue" element={<Profile />} />
path: 'notifications/', </Route>
element: <Notifications /> <Route path="/" errorElement={<ErrorPage />}>
}, <Route path="/login" element={<Login />} />,
{ <Route path="/logged-in" element={<Logged_In />} />
path: 'playground/', <Route path="/reset-password" element={<Reset />} />
element: <Playground /> <Route path="/set-password" element={<Set_Password />} />
}, </Route>
{ </Routes>
path: 'scan',
element: <Scan />
},
{
path: 'part/',
element: <CategoryDetail />
},
{
path: 'part/category/:id',
element: <CategoryDetail />
},
{
path: 'part/:id',
element: <PartDetail />
},
{
path: 'stock/',
element: <LocationDetail />
},
{
path: 'stock/location/:id',
element: <LocationDetail />
},
{
path: 'stock/item/:id',
element: <StockDetail />
},
{
path: 'build/',
element: <BuildIndex />
},
{
path: 'build/:id',
element: <BuildDetail />
},
{
path: '/profile/:tabValue',
element: <Profile />
}
]
},
{
path: '/login',
element: <Login />,
errorElement: <ErrorPage />
},
{
path: '/logged-in',
element: <Logged_In />,
errorElement: <ErrorPage />
},
{
path: '/reset-password',
element: <Reset />,
errorElement: <ErrorPage />
},
{
path: '/set-password',
element: <Set_Password />,
errorElement: <ErrorPage />
}
],
{ basename: '/platform' }
); );

View File

@ -1,11 +1,11 @@
import { QueryClientProvider } from '@tanstack/react-query'; import { QueryClientProvider } from '@tanstack/react-query';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { RouterProvider } from 'react-router-dom'; import { BrowserRouter } from 'react-router-dom';
import { queryClient, setApiDefaults } from '../App'; import { queryClient, setApiDefaults } from '../App';
import { BaseContext } from '../contexts/BaseContext'; import { BaseContext } from '../contexts/BaseContext';
import { defaultHostList } from '../defaults/defaultHostList'; import { defaultHostList } from '../defaults/defaultHostList';
import { router } from '../router'; import { routes } from '../router';
import { useApiState } from '../states/ApiState'; import { useApiState } from '../states/ApiState';
import { useLocalState } from '../states/LocalState'; import { useLocalState } from '../states/LocalState';
import { useSessionState } from '../states/SessionState'; import { useSessionState } from '../states/SessionState';
@ -35,7 +35,7 @@ export default function DesktopAppView() {
return ( return (
<BaseContext> <BaseContext>
<QueryClientProvider client={queryClient}> <QueryClientProvider client={queryClient}>
<RouterProvider router={router} /> <BrowserRouter basename="platform">{routes}</BrowserRouter>
</QueryClientProvider> </QueryClientProvider>
</BaseContext> </BaseContext>
); );