fix(nav): use segment-boundary route matching to prevent false positives

Extracts isActiveRoute() into shared nav module. Matches exact path
or path + '/' prefix, preventing /settings from matching /settings-advanced.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 14:00:18 +02:00
parent aeaca76534
commit bd8e901685
5 changed files with 29 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';
import { desktopNavSections } from './nav';
import { desktopNavSections, isActiveRoute } from './nav';
let { appName, householdName }: { appName: string; householdName: string } = $props();
</script>
@@ -24,7 +24,7 @@
{section.title}
</p>
{#each section.items as item (item.href)}
{@const active = $page.url.pathname.startsWith(item.href)}
{@const active = isActiveRoute(item.href, $page.url.pathname)}
<a
href={item.href}
aria-current={active ? 'page' : undefined}