@@ -3,7 +3,7 @@ import type { CSSObject, Interpolation, Theme } from "@emotion/react";
3
3
import { Stack } from "components/Stack/Stack" ;
4
4
import { type ClassName , useClassName } from "hooks/useClassName" ;
5
5
import type { ElementType , FC , ReactNode } from "react" ;
6
- import { Link , NavLink } from "react-router-dom" ;
6
+ import { Link , NavLink , useLocation } from "react-router-dom" ;
7
7
import { cn } from "utils/cn" ;
8
8
9
9
interface SidebarProps {
@@ -61,6 +61,18 @@ export const SettingsSidebarNavItem: FC<SettingsSidebarNavItemProps> = ({
61
61
href,
62
62
end,
63
63
} ) => {
64
+
65
+ const location = useLocation ( ) ;
66
+ if ( end ) {
67
+ console . log ( 'Current Path:' , location . pathname ) ;
68
+ console . log ( 'NavLink href:' , href ) ;
69
+ }
70
+
71
+ const normalizePath = ( path : string ) =>
72
+ path . endsWith ( '/' ) ? path . slice ( 0 , - 1 ) : path ;
73
+
74
+ const isInitiallyActive =
75
+ normalizePath ( location . pathname ) === normalizePath ( href ) ;
64
76
return (
65
77
< NavLink
66
78
end = { end }
@@ -69,7 +81,7 @@ export const SettingsSidebarNavItem: FC<SettingsSidebarNavItemProps> = ({
69
81
cn (
70
82
"relative text-sm text-content-secondary no-underline font-medium py-2 px-3 hover:bg-surface-secondary rounded-md transition ease-in-out duration-150" ,
71
83
{
72
- "font-semibold text-content-primary" : isActive ,
84
+ "font-semibold text-content-primary" : isActive || isInitiallyActive ,
73
85
} ,
74
86
)
75
87
}
0 commit comments