Skip to content

Commit

Permalink
fix: fixed routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilhelm Vold committed Nov 22, 2023
1 parent db7d9c5 commit c808afc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const Table = ({ refetchKey }: { refetchKey: number }) => {
cell: ({ row }) => (
<Button
onClick={() => {
navigate(`/model/${row.original.analogueModelId}/details`);
navigate(`/${row.original.analogueModelId}/details`);
}}
>
Go to model
Expand Down
6 changes: 0 additions & 6 deletions src/features/AppBar/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Tabs } from '@equinor/eds-core-react';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { tabs } from '../../../router';
import * as Styled from './Navigation.styled';
Expand All @@ -11,11 +10,6 @@ export const Navigation = () => {
(tab) => `/${tab.path}` === window.location.pathname,
);

useEffect(() => {
const currentURL = window.location.pathname;
if (currentURL === '/') navigate('models');
}, [navigate]);

function clickTab(tab: number) {
navigate(tabs[tab].path);
}
Expand Down
25 changes: 17 additions & 8 deletions src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@ interface Tab extends Required<Pick<NonIndexRouteObject, 'path' | 'element'>> {
}

const tabs: Tab[] = [
{
title: 'Models',
path: 'models',
element: <Browse />,
},
{ title: 'Models', path: '/', element: <Browse /> },
{ title: 'API', path: 'api', element: <Api /> },
{ title: 'About', path: 'about', element: <About /> },
];
const appRoutes = (tabs as NonIndexRouteObject[]).concat([

const appRoutes = [
{
index: true,
element: <Browse />,
},
{
path: 'model/:modelId/',
path: 'api',
element: <Api />,
},
{
path: 'about',
element: <About />,
},
{
path: ':modelId/',
element: <Model />,
children: [
{
Expand All @@ -48,7 +57,7 @@ const appRoutes = (tabs as NonIndexRouteObject[]).concat([
},
],
},
]);
];

const router = createBrowserRouter([
{
Expand Down

0 comments on commit c808afc

Please sign in to comment.