Skip to content

Commit dd8be35

Browse files
committed
fix: normalize path for isActive
1 parent baccb91 commit dd8be35

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/i18n/utils.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ export function useTranslations(lang?: Lang) {
1818
};
1919
}
2020

21+
function normalizePath(path: string): string {
22+
return path === '/' ? path : path.replace(/\/$/, '');
23+
}
24+
2125
export function isActive(linkPath: string, currentPath: string): boolean {
22-
const normalizedLink = linkPath.replace(/\/$/, '') || '/';
23-
const normalizedCurrent = currentPath.replace(/\/$/, '') || '/';
24-
return normalizedLink === normalizedCurrent;
26+
const normalizedLink = normalizePath(linkPath);
27+
const normalizedCurrent = normalizePath(currentPath);
28+
return normalizedLink.endsWith(normalizedCurrent);
2529
}

0 commit comments

Comments
 (0)