@@ -15,6 +15,7 @@ import useMediaQuery from "@mui/material/useMediaQuery";
15
15
import { signOut , useSession } from "next-auth/react" ;
16
16
import Image from "next/image" ;
17
17
import Link from "next/link" ;
18
+ import { useRouter } from "next/router" ;
18
19
import * as React from "react" ;
19
20
import { MouseEventHandler } from "react" ;
20
21
import $navbar from "./Navbar.module.css" ;
@@ -29,6 +30,7 @@ interface NavItemProps {
29
30
export default function NavBar ( ) {
30
31
const [ mobileOpen , setMobileOpen ] = React . useState ( false ) ;
31
32
const desktop = useMediaQuery ( "(min-width: 992px)" ) ;
33
+ const router = useRouter ( ) ;
32
34
33
35
const { status } = useSession ( ) ;
34
36
@@ -64,16 +66,25 @@ export default function NavBar() {
64
66
</ Toolbar >
65
67
) ;
66
68
67
- const NavItem = ( { href, icon, text, onClick } : NavItemProps ) => (
68
- < ListItem disablePadding className = { $navbar . linkItem } >
69
- < Link href = { href || "" } className = { $navbar . link } >
70
- { icon }
71
- < p className = { $navbar . linkTitle } onClick = { onClick } >
72
- { text }
73
- </ p >
69
+ const NavItem = ( { href, icon, text, onClick } : NavItemProps ) => {
70
+ const currentPath = router . pathname ;
71
+ const selectedPath = currentPath . includes ( href as string ) ;
72
+
73
+ return (
74
+ < Link
75
+ href = { href || "" }
76
+ className = { `${ $navbar . link }
77
+ ${ selectedPath ? $navbar . linkSelected : "" } ` }
78
+ >
79
+ < ListItem disablePadding className = { $navbar . linkItem } >
80
+ { icon }
81
+ < p className = { $navbar . linkTitle } onClick = { onClick } >
82
+ { text }
83
+ </ p >
84
+ </ ListItem >
74
85
</ Link >
75
- </ ListItem >
76
- ) ;
86
+ ) ;
87
+ } ;
77
88
78
89
const drawer = (
79
90
< div className = { $navbar . sidebar } >
0 commit comments