Function
isNavItemActive
({
disabled,
external,
href,
matcher,
pathname,
}: Pick<NavItemConfig, 'disabled' | 'external' | 'href' | 'matcher'> & { pathname: string })
Source from the content-addressed store, hash-verified
| 1 | import type { NavItemConfig } from '@/types/nav'; |
| 2 | |
| 3 | export function isNavItemActive({ |
| 4 | disabled, |
| 5 | external, |
| 6 | href, |
| 7 | matcher, |
| 8 | pathname, |
| 9 | }: Pick<NavItemConfig, 'disabled' | 'external' | 'href' | 'matcher'> & { pathname: string }): boolean { |
| 10 | if (disabled || !href || external) { |
| 11 | return false; |
| 12 | } |
| 13 | |
| 14 | if (matcher) { |
| 15 | if (matcher.type === 'startsWith') { |
| 16 | return pathname.startsWith(matcher.href); |
| 17 | } |
| 18 | |
| 19 | if (matcher.type === 'equals') { |
| 20 | return pathname === matcher.href; |
| 21 | } |
| 22 | |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | return pathname === href; |
| 27 | } |
Tested by
no test coverage detected