From dcc5a4759bb216181bd00522270b00a1999067ac Mon Sep 17 00:00:00 2001 From: Mathias Oppedal Heggelund <98742460+mheggelund@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:45:08 +0100 Subject: [PATCH 1/2] fix: test rewrite router (#219) --- src/features/AppBar/Navigation/Navigation.tsx | 12 ++- src/router.tsx | 86 ++++++++----------- 2 files changed, 48 insertions(+), 50 deletions(-) diff --git a/src/features/AppBar/Navigation/Navigation.tsx b/src/features/AppBar/Navigation/Navigation.tsx index f3cc07bf..5946c08e 100644 --- a/src/features/AppBar/Navigation/Navigation.tsx +++ b/src/features/AppBar/Navigation/Navigation.tsx @@ -1,8 +1,18 @@ import { Tabs } from '@equinor/eds-core-react'; import { useNavigate } from 'react-router-dom'; -import { tabs } from '../../../router'; import * as Styled from './Navigation.styled'; +interface Tab { + title: string; + path: string; +} + +const tabs: Tab[] = [ + { title: 'Models', path: '/' }, + { title: 'API', path: 'api' }, + { title: 'About', path: 'about' }, +]; + export const Navigation = () => { const navigate = useNavigate(); diff --git a/src/router.tsx b/src/router.tsx index 5eeffc0b..d4d77f34 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,4 +1,4 @@ -import { createBrowserRouter, NonIndexRouteObject } from 'react-router-dom'; +import { createBrowserRouter } from 'react-router-dom'; import { App } from './App'; import { ModelView } from './features/ModelView/ModelView'; import { About } from './pages/About/About'; @@ -11,69 +11,57 @@ import { Model } from './pages/ModelPages/Model/Model'; import { ObjectResult } from './pages/ModelPages/Results/ObjectResult/ObjectResult'; import { VariogramResults } from './pages/ModelPages/Results/VariogramResults/VariogramResults'; -interface Tab extends Required> { - title: string; -} - -const tabs: Tab[] = [ - { title: 'Models', path: '/', element: }, - { title: 'API', path: 'api', element: }, - { title: 'About', path: 'about', element: }, -]; - -const appRoutes = [ - { - index: true, - element: , - }, - { - path: 'api', - element: , - }, - { - path: 'about', - element: , - }, +const router = createBrowserRouter([ { - path: ':modelId/', - element: , + path: '/', + element: , children: [ { - path: 'details', - element: , + index: true, + element: , }, - { - path: 'compute/variogram', - element: , + path: 'api', + element: , }, { - path: 'compute/object', - element: , - }, - - { - path: 'results/variogram', - element: , + path: 'about', + element: , }, { - path: 'results/object', - element: , + path: ':modelId/', + element: , + children: [ + { + path: 'details', + element: , + }, + + { + path: 'compute/variogram', + element: , + }, + { + path: 'compute/object', + element: , + }, + + { + path: 'results/variogram', + element: , + }, + { + path: 'results/object', + element: , + }, + ], }, ], }, -]; - -const router = createBrowserRouter([ - { - path: '/', - element: , - children: appRoutes, - }, { path: '*', element: , }, ]); -export { router, tabs }; +export { router }; From 6b5b27ff6d368f27278dad0dc52f850ac2b5fd83 Mon Sep 17 00:00:00 2001 From: Mathias Oppedal Heggelund <98742460+mheggelund@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:00:28 +0100 Subject: [PATCH 2/2] Fix/refresh (#220) * fix: test rewrite router * fix: test rewrite app, index, layout, router order --- src/App.tsx | 7 ++++--- src/index.tsx | 7 +++---- src/router.tsx | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 966b588e..56bc52e4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,12 +1,13 @@ +import { InteractionType } from '@azure/msal-browser'; import { AuthenticatedTemplate, UnauthenticatedTemplate, useMsalAuthentication, } from '@azure/msal-react'; -import { InteractionType } from '@azure/msal-browser'; -import { Layout } from './pages/Layout'; +import { RouterProvider } from 'react-router-dom'; import { OpenAPI } from './api/generated'; import { apiConfig } from './auth/authConfig'; +import { router } from './router'; export function App() { useMsalAuthentication(InteractionType.Redirect); @@ -15,7 +16,7 @@ export function App() { return ( <> - +
You are not authorized
diff --git a/src/index.tsx b/src/index.tsx index cf733975..88c51c0b 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,14 +1,13 @@ import { MsalProvider } from '@azure/msal-react'; import { QueryClientProvider } from '@tanstack/react-query'; +import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import React from 'react'; import ReactDOM from 'react-dom/client'; -import { RouterProvider } from 'react-router-dom'; +import { App } from './App'; import { msalInstance } from './auth/msalClient'; import { queryClient } from './auth/queryClient'; import './index.css'; import reportWebVitals from './reportWebVitals'; -import { router } from './router'; -import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement, @@ -17,7 +16,7 @@ root.render( - + diff --git a/src/router.tsx b/src/router.tsx index d4d77f34..122d689d 100644 --- a/src/router.tsx +++ b/src/router.tsx @@ -1,10 +1,11 @@ import { createBrowserRouter } from 'react-router-dom'; -import { App } from './App'; + import { ModelView } from './features/ModelView/ModelView'; import { About } from './pages/About/About'; import { Api } from './pages/Api/Api'; import { Browse } from './pages/Browse/Browse'; import { InvalidURL } from './pages/InvalidURL/InvalidURL'; +import { Layout } from './pages/Layout'; import { ComputeObject } from './pages/ModelPages/Compute/ComputeObject/ComputeObject'; import { ComputeVariogram } from './pages/ModelPages/Compute/ComputeVariogram/ComputeVariogram'; import { Model } from './pages/ModelPages/Model/Model'; @@ -14,7 +15,8 @@ import { VariogramResults } from './pages/ModelPages/Results/VariogramResults/Va const router = createBrowserRouter([ { path: '/', - element: , + element: , + children: [ { index: true,