mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
Strip trailing slashes from routes / breadcrumbs / titles
This commit is contained in:
@ -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}`;
|
||||
|
@ -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];
|
||||
|
Reference in New Issue
Block a user