@@ -23,9 +23,21 @@ interface BreadcrumbItem {
2323 isActive: boolean ;
2424}
2525
26+ function normalizePath(path : string ): string {
27+ console .log (path )
28+ if (! path ) return " "
29+ if (path === " /" ) return " /" ;
30+ return path .replace (/ \/ + $ / , " " );
31+ }
32+
33+ const normalizedCurrentPath = normalizePath (currentPath );
34+
35+ // Recursive function to build breadcrumb trail
2636function findBreadcrumbTrail(items : any [], currentPath : string , parentName ? : string ): BreadcrumbItem [] {
2737 for (const item of items ) {
28- if (item .path === currentPath ) {
38+ const itemPath = normalizePath (item .path );
39+
40+ if (itemPath === currentPath ) {
2941 const breadcrumb: BreadcrumbItem = {
3042 name: item .name ,
3143 path: item .path ,
@@ -53,21 +65,22 @@ function findBreadcrumbTrail(items: any[], currentPath: string, parentName?: str
5365 return [];
5466}
5567
68+ // Build the breadcrumb trail
5669const breadcrumbs: BreadcrumbItem [] = [];
5770
5871breadcrumbs .push ({
5972 name: homeLabel ,
6073 path: homePath ,
61- isActive: currentPath === homePath
74+ isActive: normalizedCurrentPath === normalizePath ( homePath )
6275});
6376
64- if (currentPath !== homePath && linksData ?.header ) {
65- const trail = findBreadcrumbTrail (linksData .header , currentPath );
77+ if (normalizedCurrentPath !== normalizePath ( homePath ) && linksData ?.header ) {
78+ const trail = findBreadcrumbTrail (linksData .header , normalizedCurrentPath );
6679 breadcrumbs .push (... trail );
6780}
6881
69- if (breadcrumbs .length === 1 && currentPath !== homePath ) {
70- const pathSegments = currentPath .split (' /' ).filter (Boolean );
82+ if (breadcrumbs .length === 1 && normalizedCurrentPath !== normalizePath ( homePath ) ) {
83+ const pathSegments = normalizedCurrentPath .split (' /' ).filter (Boolean );
7184 const lastSegment = pathSegments [pathSegments .length - 1 ];
7285
7386 if (lastSegment ) {
0 commit comments