fix(nav-main): improve path normalization in isActive function
This commit is contained in:
@@ -26,10 +26,15 @@ export function NavMain({
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
|
|
||||||
const isActive = (itemUrl: string) => {
|
const isActive = (itemUrl: string) => {
|
||||||
if (itemUrl === "/") {
|
const normalizePath = (path: string) =>
|
||||||
return pathname === itemUrl
|
path !== "/" ? path.replace(/\/+$/, "") : path
|
||||||
|
const currentPath = normalizePath(pathname)
|
||||||
|
const targetPath = normalizePath(itemUrl)
|
||||||
|
|
||||||
|
if (targetPath === "/" || targetPath === "/dashboard") {
|
||||||
|
return currentPath === targetPath
|
||||||
}
|
}
|
||||||
return pathname === itemUrl || pathname.startsWith(itemUrl + "/")
|
return currentPath === targetPath || currentPath.startsWith(targetPath + "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user