Skip to content

Commit

Permalink
fix: test rewrite router
Browse files Browse the repository at this point in the history
  • Loading branch information
mheggelund committed Jan 31, 2024
1 parent d46acfc commit 8300231
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 50 deletions.
12 changes: 11 additions & 1 deletion src/features/AppBar/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
86 changes: 37 additions & 49 deletions src/router.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Pick<NonIndexRouteObject, 'path' | 'element'>> {
title: string;
}

const tabs: Tab[] = [
{ title: 'Models', path: '/', element: <Browse /> },
{ title: 'API', path: 'api', element: <Api /> },
{ title: 'About', path: 'about', element: <About /> },
];

const appRoutes = [
{
index: true,
element: <Browse />,
},
{
path: 'api',
element: <Api />,
},
{
path: 'about',
element: <About />,
},
const router = createBrowserRouter([
{
path: ':modelId/',
element: <Model />,
path: '/',
element: <App />,
children: [
{
path: 'details',
element: <ModelView />,
index: true,
element: <Browse />,
},

{
path: 'compute/variogram',
element: <ComputeVariogram />,
path: 'api',
element: <Api />,
},
{
path: 'compute/object',
element: <ComputeObject />,
},

{
path: 'results/variogram',
element: <VariogramResults />,
path: 'about',
element: <About />,
},
{
path: 'results/object',
element: <ObjectResult />,
path: ':modelId/',
element: <Model />,
children: [
{
path: 'details',
element: <ModelView />,
},

{
path: 'compute/variogram',
element: <ComputeVariogram />,
},
{
path: 'compute/object',
element: <ComputeObject />,
},

{
path: 'results/variogram',
element: <VariogramResults />,
},
{
path: 'results/object',
element: <ObjectResult />,
},
],
},
],
},
];

const router = createBrowserRouter([
{
path: '/',
element: <App />,
children: appRoutes,
},
{
path: '*',
element: <InvalidURL />,
},
]);

export { router, tabs };
export { router };

0 comments on commit 8300231

Please sign in to comment.