11'use client' ;
22
33import React , { useState } from 'react' ;
4- import Link from 'next/link' ;
54import Box from '@mui/material/Box' ;
65import List from '@mui/material/List' ;
76import ListItem from '@mui/material/ListItem' ;
@@ -11,8 +10,9 @@ import Collapse from '@mui/material/Collapse';
1110import Typography from '@mui/material/Typography' ;
1211import ExpandLess from '@mui/icons-material/ExpandLess' ;
1312import ExpandMore from '@mui/icons-material/ExpandMore' ;
14- import MuiLink from '@mui/material/Link' ;
13+ import Link from '@mui/material/Link' ;
1514import type { NavigationItem } from './types' ;
15+ import { usePathname } from "next/navigation" ;
1616
1717function NavigationFolder ( { items, level = 0 } : { items : NavigationItem [ ] ; level ?: number } ) {
1818 return (
@@ -25,6 +25,9 @@ function NavigationFolder({ items, level = 0 }: { items: NavigationItem[]; level
2525}
2626
2727function NavigationNode ( { item, level } : { item : NavigationItem ; level : number } ) {
28+
29+ const pathname = usePathname ( )
30+
2831 const [ open , setOpen ] = useState ( level < 1 ) ;
2932 const hasChildren = ! ! item . children && item . children . length > 0 ;
3033 if ( hasChildren ) {
@@ -47,13 +50,16 @@ function NavigationNode({ item, level }: { item: NavigationItem; level: number }
4750 </ >
4851 ) ;
4952 }
53+
5054 // Leaf node (link)
55+ const href = `/${ item . path ?. replace ( / \. m d x ? $ | \/ i n d e x \. m d $ / , '' ) || '' } /`
56+ const isActive = pathname === href
5157 return (
52- < ListItem disablePadding sx = { { pl : ( level + 1 ) * 2 } } >
53- < MuiLink component = { Link } href = { `/ ${ item . path ?. replace ( / \. m d x ? $ | \/ i n d e x \. m d $ / , '' ) || '' } ` } underline = "hover" color = "inherit" >
54- < ListItemText primary = { item . label } />
55- </ MuiLink >
56- </ ListItem >
58+ < Link href = { href } underline = "hover" color = { isActive ? 'primary.main' : 'text.primary' } fontWeight = { isActive ? 600 : 400 } >
59+ < ListItem sx = { { pl : ( level + 1 ) * 2 } } >
60+ { item . label }
61+ </ ListItem >
62+ </ Link >
5763 ) ;
5864}
5965
0 commit comments