u
This commit is contained in:
55
src/nav.js
55
src/nav.js
@@ -20,15 +20,6 @@ export const NAV_ITEMS = [
|
||||
{ path: '/infos', label: 'Infos', icon: InfoIcon },
|
||||
];
|
||||
|
||||
export function isNavItemActive(pathname, navPath) {
|
||||
if (navPath === '/artikel') {
|
||||
return pathname === navPath
|
||||
|| pathname.startsWith(`${navPath}/`)
|
||||
|| isKategorienPath(pathname);
|
||||
}
|
||||
return pathname === navPath || pathname.startsWith(`${navPath}/`);
|
||||
}
|
||||
|
||||
export const SUB_NAV = {
|
||||
'/artikel': [
|
||||
{ segment: '', icon: ViewListIcon },
|
||||
@@ -45,3 +36,49 @@ export const SUB_NAV = {
|
||||
{ segment: 'kontakte', label: 'Kontakte', icon: ContactPageIcon },
|
||||
],
|
||||
};
|
||||
|
||||
export function isNavItemActive(pathname, navPath) {
|
||||
if (navPath === '/artikel') {
|
||||
return (
|
||||
pathname === navPath ||
|
||||
pathname.startsWith(`${navPath}/`) ||
|
||||
isKategorienPath(pathname)
|
||||
);
|
||||
}
|
||||
return pathname === navPath || pathname.startsWith(`${navPath}/`);
|
||||
}
|
||||
|
||||
/** Stable across article tab changes (e.g. always `/artikel`). */
|
||||
export function resolveActiveNav(pathname) {
|
||||
for (const item of NAV_ITEMS) {
|
||||
if (isNavItemActive(pathname, item.path)) return item.path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Active sub-nav segment for a section.
|
||||
* `''` = section index, `null` = none (e.g. article detail tabs).
|
||||
*/
|
||||
export function resolveActiveSub(pathname, sectionPath) {
|
||||
const subNav = SUB_NAV[sectionPath];
|
||||
if (!subNav) return null;
|
||||
|
||||
const knownSegments = new Set(subNav.map((item) => item.segment).filter(Boolean));
|
||||
const rest = pathname.slice(sectionPath.length).replace(/^\//, '').split('/')[0];
|
||||
const isArticleDetail =
|
||||
sectionPath === '/artikel' &&
|
||||
!isKategorienPath(pathname) &&
|
||||
rest &&
|
||||
!knownSegments.has(rest);
|
||||
if (isArticleDetail) return null;
|
||||
|
||||
const active = subNav.find((item) => {
|
||||
if (item.segment === 'kategorien') {
|
||||
return isKategorienPath(pathname);
|
||||
}
|
||||
const subPath = item.segment ? `${sectionPath}/${item.segment}` : sectionPath;
|
||||
return pathname === subPath || pathname === `${subPath}/`;
|
||||
});
|
||||
return active ? active.segment : null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user