From 60e57f1f5f57a08b29f90c23fa04442c2d43ec17 Mon Sep 17 00:00:00 2001 From: prplwtf Date: Sat, 17 Feb 2024 22:00:00 +0100 Subject: [PATCH] feat `routes`: Make routes work even if there are none. --- .../extends/routers/DashboardRouter.tsx | 4 ++-- .../blueprint/extends/routers/ServerRouter.tsx | 4 ++-- .../blueprint/extends/routers/routes.ts | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/resources/scripts/blueprint/extends/routers/DashboardRouter.tsx b/resources/scripts/blueprint/extends/routers/DashboardRouter.tsx index e3d12c7..1573ed5 100644 --- a/resources/scripts/blueprint/extends/routers/DashboardRouter.tsx +++ b/resources/scripts/blueprint/extends/routers/DashboardRouter.tsx @@ -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 }) => ( @@ -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 }) => ( diff --git a/resources/scripts/blueprint/extends/routers/ServerRouter.tsx b/resources/scripts/blueprint/extends/routers/ServerRouter.tsx index e649f3a..4fd6187 100644 --- a/resources/scripts/blueprint/extends/routers/ServerRouter.tsx +++ b/resources/scripts/blueprint/extends/routers/ServerRouter.tsx @@ -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 }) => ( diff --git a/resources/scripts/blueprint/extends/routers/routes.ts b/resources/scripts/blueprint/extends/routers/routes.ts index 99b8e16..d37ddc0 100644 --- a/resources/scripts/blueprint/extends/routers/routes.ts +++ b/resources/scripts/blueprint/extends/routers/routes.ts @@ -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; \ No newline at end of file +} as Routes; \ No newline at end of file