feat routes: Make routes work even if there are none.

This commit is contained in:
prplwtf 2024-02-17 22:00:00 +01:00
parent 1adf071d2e
commit 60e57f1f5f
3 changed files with 18 additions and 8 deletions

View file

@ -23,7 +23,7 @@ export const NavigationLinks = () => {
))}
{/* Blueprint routes */}
{blueprintRoutes.account
{blueprintRoutes.account.length > 0 && blueprintRoutes.account
.filter((route) => !!route.name)
.map(({ path, name, exact = false }) => (
<NavLink key={path} to={`/account/${path}`.replace('//', '/')} exact={exact}>
@ -54,7 +54,7 @@ export const NavigationRouter = () => {
))}
{/* Blueprint routes */}
{blueprintRoutes.account.map(({ path, component: Component }) => (
{blueprintRoutes.account.length > 0 && blueprintRoutes.account.map(({ path, component: Component }) => (
<Route key={path} path={`/account/${path}`.replace('//', '/')} exact>
<Component />
</Route>

View file

@ -40,7 +40,7 @@ export const NavigationLinks = () => {
)}
{/* Blueprint routes */}
{blueprintRoutes.server
{blueprintRoutes.server.length > 0 && blueprintRoutes.server
.filter((route) => !!route.name)
.map((route) =>
route.permission ? (
@ -85,7 +85,7 @@ export const NavigationRouter = () => {
))}
{/* Blueprint routes */}
{blueprintRoutes.server.map(({ path, permission, component: Component }) => (
{blueprintRoutes.server.length > 0 && blueprintRoutes.server.map(({ path, permission, component: Component }) => (
<PermissionRoute key={path} permission={permission} path={to(path)} exact>
<Spinner.Suspense>
<Component />

View file

@ -2,9 +2,19 @@ import React from 'react';
/* blueprint/import */
interface ExtendedRouteDefinition { path: string; name: string | undefined; component: React.ComponentType; exact?: boolean; }
interface ExtendedServerRouteDefinition extends ExtendedRouteDefinition { permission: string | string[] | null; }
interface ExtendedRoutes { account: ExtendedRouteDefinition[]; server: ExtendedServerRouteDefinition[]; }
interface RouteDefinition {
path: string;
name: string | undefined;
component: React.ComponentType;
exact?: boolean;
}
interface ServerRouteDefinition extends RouteDefinition {
permission: string | string[] | null;
}
interface Routes {
account: RouteDefinition[];
server: ServerRouteDefinition[];
}
export default {
account: [
@ -13,4 +23,4 @@ export default {
server: [
/* routes/server */
],
} as ExtendedRoutes;
} as Routes;