fix(nav-main): improve path normalization in isActive function

This commit is contained in:
mlogclub
2026-04-24 21:31:17 +08:00
parent 7f7da35fe6
commit 4f633b3794
+8 -3
View File
@@ -26,10 +26,15 @@ export function NavMain({
const pathname = usePathname()
const isActive = (itemUrl: string) => {
if (itemUrl === "/") {
return pathname === itemUrl
const normalizePath = (path: string) =>
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 (