fix(frontend): normalisasi trailing slash pada isActivePath agar nav aktif terdeteksi

This commit is contained in:
asepharyana
2026-08-24 17:44:42 +07:00
parent 5f42c17caa
commit 1c8c0ca081
+4 -2
View File
@@ -75,6 +75,8 @@ export const mobileNavItems: NavItem[] = navItems.filter((item) =>
export type NavItemId = (typeof navItems)[number]["href"]; export type NavItemId = (typeof navItems)[number]["href"];
export function isActivePath(pathname: string, matchPrefix: string): boolean { export function isActivePath(pathname: string, matchPrefix: string): boolean {
if (matchPrefix === "/dashboard") return pathname === "/dashboard"; // trailingSlash builds surface "/x/" via usePathname — normalize first.
return pathname.startsWith(matchPrefix); const path = pathname.replace(/\/+$/, "") || "/";
if (matchPrefix === "/dashboard") return path === "/dashboard";
return path.startsWith(matchPrefix);
} }