u
This commit is contained in:
@@ -1,27 +1,34 @@
|
||||
import { Outlet, useLocation } from 'react-router-dom';
|
||||
import PageLayout from './PageLayout';
|
||||
import { NAV_ITEMS, SUB_NAV } from '../nav';
|
||||
import { isKategorienPath } from '../pages/artikel/categoryRoute';
|
||||
|
||||
export default function SectionLayout({ sectionPath }) {
|
||||
const { pathname } = useLocation();
|
||||
const title = NAV_ITEMS.find((item) => item.path === sectionPath)?.label ?? '';
|
||||
const subNav = SUB_NAV[sectionPath];
|
||||
const activeSub = subNav?.find((item) => {
|
||||
if (item.segment === 'kategorien') {
|
||||
return isKategorienPath(pathname);
|
||||
}
|
||||
const subPath = item.segment ? `${sectionPath}/${item.segment}` : sectionPath;
|
||||
return pathname === subPath || pathname === `${subPath}/`;
|
||||
});
|
||||
|
||||
const knownSegments = new Set((subNav ?? []).map((item) => item.segment).filter(Boolean));
|
||||
const rest = pathname.slice(sectionPath.length).replace(/^\//, '').split('/')[0];
|
||||
const detailSku =
|
||||
sectionPath === '/artikel' && rest && !knownSegments.has(rest)
|
||||
? decodeURIComponent(rest)
|
||||
: null;
|
||||
const isArticleDetail =
|
||||
sectionPath === '/artikel' &&
|
||||
!isKategorienPath(pathname) &&
|
||||
rest &&
|
||||
!knownSegments.has(rest);
|
||||
|
||||
const pageTitle = detailSku ?? (activeSub && subNav ? activeSub.label : title);
|
||||
const pageTitle = isArticleDetail
|
||||
? title
|
||||
: (activeSub?.label ?? title);
|
||||
|
||||
return (
|
||||
<PageLayout title={pageTitle} subNav={subNav} basePath={sectionPath}>
|
||||
<PageLayout title={pageTitle} showTitle={!isArticleDetail} subNav={subNav} basePath={sectionPath}>
|
||||
<Outlet />
|
||||
</PageLayout>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user