Files
rheinsw-mono-repo/internal_frontend/utils/BreadcrumbUtils.ts

27 lines
754 B
TypeScript

import {breadcrumbMap} from "@/lib/breadcrumb-map";
export interface Breadcrumb {
href: string;
label: string;
isCurrentPage: boolean;
}
export function getBreadcrumbs(path: string): Breadcrumb[] {
const pathSegments = path.split('/').filter(Boolean);
return pathSegments.map((segment, index) => {
const href = `/${pathSegments.slice(0, index + 1).join('/')}`;
const label =
breadcrumbMap[segment.toLowerCase()] ||
segment
.split('-')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
return {
label,
href,
isCurrentPage: index === pathSegments.length - 1,
};
});
}