mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 05:10: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
|
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 routes: string[] | any = route.slice(0, -1);
|
||||||
const {pageHeader, pathToLabelMap, branding} = useContext(QContext);
|
const {pageHeader, pathToLabelMap, branding} = useContext(QContext);
|
||||||
|
|
||||||
const fullPathToLabel = (fullPath: string, route: string): string =>
|
const fullPathToLabel = (fullPath: string, route: string): string =>
|
||||||
{
|
{
|
||||||
|
if(fullPath.endsWith("/"))
|
||||||
|
{
|
||||||
|
fullPath = fullPath.replace(/\/+$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
if(pathToLabelMap && pathToLabelMap[fullPath])
|
if(pathToLabelMap && pathToLabelMap[fullPath])
|
||||||
{
|
{
|
||||||
return pathToLabelMap[fullPath];
|
return pathToLabelMap[fullPath];
|
||||||
@ -82,6 +96,11 @@ function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(routes[i] === "")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
accumulatedPath = `${accumulatedPath}/${routes[i]}`;
|
accumulatedPath = `${accumulatedPath}/${routes[i]}`;
|
||||||
fullRoutes.push(accumulatedPath);
|
fullRoutes.push(accumulatedPath);
|
||||||
pageTitle = `${fullPathToLabel(accumulatedPath, routes[i])} | ${pageTitle}`;
|
pageTitle = `${fullPathToLabel(accumulatedPath, routes[i])} | ${pageTitle}`;
|
||||||
|
@ -215,6 +215,11 @@ function NavBar({absolute, light, isMini}: Props): JSX.Element
|
|||||||
const {pathToLabelMap} = useContext(QContext);
|
const {pathToLabelMap} = useContext(QContext);
|
||||||
const fullPathToLabel = (fullPath: string, route: string): string =>
|
const fullPathToLabel = (fullPath: string, route: string): string =>
|
||||||
{
|
{
|
||||||
|
if(fullPath.endsWith("/"))
|
||||||
|
{
|
||||||
|
fullPath = fullPath.replace(/\/+$/, "");
|
||||||
|
}
|
||||||
|
|
||||||
if(pathToLabelMap && pathToLabelMap[fullPath])
|
if(pathToLabelMap && pathToLabelMap[fullPath])
|
||||||
{
|
{
|
||||||
return pathToLabelMap[fullPath];
|
return pathToLabelMap[fullPath];
|
||||||
|
Reference in New Issue
Block a user