fix(admin): improve breadcrumb segment matching for nested nav items
- replace fixed `[first, second]` destructuring with dynamic segment-aware matching - find nav items using prefix segment comparison instead of first-segment-only match - compute `itemSegCount` from matched nav item href to support multi-segment routes - derive sub-segment index dynamically so breadcrumb labels resolve correctly for nested paths
This commit is contained in:
@@ -47,7 +47,6 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
|
||||
const crumbs = [{ icon: DashboardSquare03Icon, href: '/admin/dashboard' }];
|
||||
const after = pathname.replace(/^\/admin\/?/, '');
|
||||
const segments = after.split('/').filter(Boolean);
|
||||
const [first, second] = segments;
|
||||
|
||||
if (!after || !segments.length || (segments[0] === 'dashboard' && segments.length === 1)) {
|
||||
crumbs.push({ label: pageTitle });
|
||||
@@ -55,8 +54,15 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
|
||||
}
|
||||
|
||||
const allItems = navigationSections.flatMap(s => s.items);
|
||||
const navItem = allItems.find(item => item.href.replace('/admin/', '').split('/')[0] === first);
|
||||
const hasSubPage = segments.length > 1;
|
||||
const navItem = allItems.find(item => {
|
||||
const itemSegs = item.href.replace('/admin/', '').split('/').filter(Boolean);
|
||||
return itemSegs.length <= segments.length && itemSegs.every((seg, i) => segments[i] === seg);
|
||||
});
|
||||
|
||||
const itemSegCount = navItem
|
||||
? navItem.href.replace('/admin/', '').split('/').filter(Boolean).length
|
||||
: 1;
|
||||
const hasSubPage = segments.length > itemSegCount;
|
||||
|
||||
if (navItem) {
|
||||
crumbs.push({ label: navItem.name, href: hasSubPage ? navItem.href : undefined });
|
||||
@@ -65,10 +71,11 @@ const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appNa
|
||||
return crumbs;
|
||||
}
|
||||
|
||||
if (second === 'new') {
|
||||
const subSegment = segments[itemSegCount];
|
||||
if (subSegment === 'new') {
|
||||
crumbs.push({ label: 'Nouveau' });
|
||||
} else if (second === 'edit') {
|
||||
const page = getPages().find(p => p.slug === `${first}:edit`);
|
||||
} else if (subSegment === 'edit') {
|
||||
const page = getPages().find(p => p.slug === `${segments[0]}:edit`);
|
||||
crumbs.push({ label: page?.breadcrumbLabel || page?.title || 'Modifier' });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user