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:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { mobileNavItems, desktopNavSections } from './nav';
|
||||
import { mobileNavItems, desktopNavSections, isActiveRoute } from './nav';
|
||||
|
||||
describe('nav config', () => {
|
||||
describe('mobileNavItems', () => {
|
||||
@@ -39,4 +39,22 @@ describe('nav config', () => {
|
||||
expect(labels).toEqual(['Mitglieder', 'Einstellungen']);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isActiveRoute', () => {
|
||||
it('matches exact route', () => {
|
||||
expect(isActiveRoute('/planner', '/planner')).toBe(true);
|
||||
});
|
||||
|
||||
it('matches sub-route', () => {
|
||||
expect(isActiveRoute('/planner', '/planner/week')).toBe(true);
|
||||
});
|
||||
|
||||
it('does not match route with similar prefix', () => {
|
||||
expect(isActiveRoute('/settings', '/settings-advanced')).toBe(false);
|
||||
});
|
||||
|
||||
it('does not match unrelated route', () => {
|
||||
expect(isActiveRoute('/planner', '/recipes')).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user