misc_pterodactyl-panel/resources/scripts/routers/DashboardRouter.tsx

53 lines
2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { NavLink, Route, Switch } from 'react-router-dom';
2019-06-26 04:28:56 +00:00
import NavigationBar from '@/components/NavigationBar';
import DashboardContainer from '@/components/dashboard/DashboardContainer';
2021-01-31 02:01:32 +00:00
import { NotFound } from '@/components/elements/ScreenBlock';
2020-07-04 16:46:26 +00:00
import TransitionRouter from '@/TransitionRouter';
import SubNavigation from '@/components/elements/SubNavigation';
import { useLocation } from 'react-router';
import Spinner from '@/components/elements/Spinner';
import routes from '@/routers/routes';
2019-06-26 04:28:56 +00:00
export default () => {
const location = useLocation();
return (
<>
<NavigationBar/>
{location.pathname.startsWith('/account') &&
<SubNavigation>
<div>
{routes.account.filter((route) => !!route.name).map(({ path, name, exact = false }) => (
<NavLink
key={path}
to={`/account/${path}`.replace('//', '/')}
exact={exact}
>
{name}
</NavLink>
))}
</div>
</SubNavigation>
}
<TransitionRouter>
<React.Suspense fallback={<Spinner centered/>}>
<Switch location={location}>
<Route path={'/'} exact>
<DashboardContainer/>
</Route>
{routes.account.map(({ path, component: Component }) => (
<Route key={path} path={`/account/${path}`.replace('//', '/')} exact>
<Component/>
</Route>
))}
<Route path={'*'}>
<NotFound/>
</Route>
</Switch>
</React.Suspense>
</TransitionRouter>
</>
);
};