@@ -8,22 +8,19 @@ import { useClientContext, useMediaQuery, useSiteNavigation } from '@/hooks';
88import type { NavigationKeys } from '@/types' ;
99import { dashToCamelCase } from '@/util/stringUtils' ;
1010
11- const WithBreadcrumbs : FC = ( ) => {
12- const { navigationItems, getSideNavigation } = useSiteNavigation ( ) ;
11+ type WithBreadcrumbsProps = {
12+ navKeys ?: Array < NavigationKeys > ;
13+ } ;
14+
15+ const WithBreadcrumbs : FC < WithBreadcrumbsProps > = ( { navKeys = [ ] } ) => {
16+ const { getSideNavigation } = useSiteNavigation ( ) ;
1317 const { pathname } = useClientContext ( ) ;
1418 const isMobileScreen = useMediaQuery ( '(max-width: 639px)' ) ;
1519
1620 const maxLength = isMobileScreen ? 2 : 4 ;
1721
1822 const getBreadrumbs = ( ) => {
19- const [ navigationKey ] =
20- navigationItems . find ( ( [ , item ] ) => pathname . includes ( item . link ) ) || [ ] ;
21-
22- if ( navigationKey === undefined ) {
23- return [ ] ;
24- }
25-
26- const navigationTree = getSideNavigation ( [ navigationKey as NavigationKeys ] ) ;
23+ const navigationTree = getSideNavigation ( navKeys ) ;
2724
2825 const pathList = pathname
2926 . split ( '/' )
@@ -34,9 +31,15 @@ const WithBreadcrumbs: FC = () => {
3431
3532 // Reduce the pathList to a breadcrumbs array by finding each path in the current navigation layer,
3633 // updating the currentNode to the found node's items(next layer) for the next iteration.
37- return pathList . reduce ( ( breadcrumbs , path ) => {
34+ return pathList . reduce ( ( breadcrumbs , path , index ) => {
3835 const nodeWithCurrentPath = currentNode . find (
39- ( [ nodePath ] ) => nodePath === path
36+ ( [ nodePath , entry ] ) =>
37+ nodePath === path &&
38+ // Skip checking child path if it is the last path since there is no more child item inside
39+ ( index === pathList . length - 1 ||
40+ entry . items . some (
41+ ( [ childPath ] ) => childPath === pathList [ index + 1 ]
42+ ) )
4043 ) ;
4144
4245 if ( nodeWithCurrentPath ) {
0 commit comments