Strip trailing slashes from routes / breadcrumbs / titles

This commit is contained in:
2023-07-19 11:16:59 -05:00
parent ba79ccb2eb
commit 95144608e5
2 changed files with 24 additions and 0 deletions

View File

@ -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}`;

View File

@ -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];