From 95144608e5dc0f5f170b43175b4e53c242189444 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Wed, 19 Jul 2023 11:16:59 -0500 Subject: [PATCH] Strip trailing slashes from routes / breadcrumbs / titles --- src/qqq/components/horseshoe/Breadcrumbs.tsx | 19 +++++++++++++++++++ src/qqq/components/horseshoe/NavBar.tsx | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/src/qqq/components/horseshoe/Breadcrumbs.tsx b/src/qqq/components/horseshoe/Breadcrumbs.tsx index b4fc4ec..f3006a4 100644 --- a/src/qqq/components/horseshoe/Breadcrumbs.tsx +++ b/src/qqq/components/horseshoe/Breadcrumbs.tsx @@ -59,11 +59,25 @@ export const routeToLabel = (route: string): string => function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element { + /////////////////////////////////////////////////////////////////////// + // strip away empty elements of the route (e.g., trailing slash(es)) // + /////////////////////////////////////////////////////////////////////// + if(route.length) + { + // @ts-ignore + route = route.filter(r => r != ""); + } + const routes: string[] | any = route.slice(0, -1); const {pageHeader, pathToLabelMap, branding} = useContext(QContext); const fullPathToLabel = (fullPath: string, route: string): string => { + if(fullPath.endsWith("/")) + { + fullPath = fullPath.replace(/\/+$/, ""); + } + if(pathToLabelMap && pathToLabelMap[fullPath]) { return pathToLabelMap[fullPath]; @@ -82,6 +96,11 @@ function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element continue; } + if(routes[i] === "") + { + continue; + } + accumulatedPath = `${accumulatedPath}/${routes[i]}`; fullRoutes.push(accumulatedPath); pageTitle = `${fullPathToLabel(accumulatedPath, routes[i])} | ${pageTitle}`; diff --git a/src/qqq/components/horseshoe/NavBar.tsx b/src/qqq/components/horseshoe/NavBar.tsx index 304d287..3e15f5d 100644 --- a/src/qqq/components/horseshoe/NavBar.tsx +++ b/src/qqq/components/horseshoe/NavBar.tsx @@ -215,6 +215,11 @@ function NavBar({absolute, light, isMini}: Props): JSX.Element const {pathToLabelMap} = useContext(QContext); const fullPathToLabel = (fullPath: string, route: string): string => { + if(fullPath.endsWith("/")) + { + fullPath = fullPath.replace(/\/+$/, ""); + } + if(pathToLabelMap && pathToLabelMap[fullPath]) { return pathToLabelMap[fullPath];