Skip to content

Commit d12cb11

Browse files
committed
Refactor urlIsActive function to improve URL matching logic
1 parent 08df299 commit d12cb11

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

resources/js/lib/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ export function cn(...inputs: ClassValue[]) {
77
}
88

99
export function urlIsActive(urlToCheck: NonNullable<InertiaLinkProps['href']>, currentUrl: string) {
10-
return toUrl(urlToCheck) === currentUrl;
10+
const checkUrl = toUrl(urlToCheck);
11+
12+
if (checkUrl === '/' && currentUrl === '/') {
13+
return true;
14+
}
15+
16+
if (checkUrl !== '/' && currentUrl.startsWith(checkUrl)) {
17+
return true;
18+
}
19+
20+
return false;
1121
}
1222

1323
export function toUrl(href: NonNullable<InertiaLinkProps['href']>) {

0 commit comments

Comments
 (0)