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

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-11-25 20:25:03 +00:00
import { Suspense } from 'react';
import { NavLink, Route, Routes, useLocation } 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';
import Spinner from '@/components/elements/Spinner';
2022-11-25 20:25:03 +00:00
import SubNavigation from '@/components/elements/SubNavigation';
import routes from '@/routers/routes';
2019-06-26 04:28:56 +00:00
2022-11-25 20:25:03 +00:00
function DashboardRouter() {
const location = useLocation();
return (
<>
<NavigationBar />
2022-11-25 20:25:03 +00:00
{location.pathname.startsWith('/account') && (
<SubNavigation>
<div>
{routes.account
2022-11-25 20:25:03 +00:00
.filter(route => route.path !== undefined)
.map(({ path, name, end = false }) => (
<NavLink key={path} to={`/account/${path ?? ''}`.replace('//', '/')} end={end}>
{name}
</NavLink>
))}
</div>
</SubNavigation>
)}
2022-11-25 20:25:03 +00:00
<Suspense fallback={<Spinner centered />}>
<Routes>
<Route path="" element={<DashboardContainer />} />
{routes.account.map(({ route, component: Component }) => (
<Route key={route} path={`/account/${route}`.replace('//', '/')} element={<Component />} />
))}
<Route path="*" element={<NotFound />} />
</Routes>
</Suspense>
</>
);
2022-11-25 20:25:03 +00:00
}
export default DashboardRouter;