Skip to content

Commit 892835c

Browse files
committed
feat: topNav.match fn
1 parent 537c06e commit 892835c

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

.changeset/new-donkeys-wish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vocs": minor
3+
---
4+
5+
Added `topNav.match` function

src/app/hooks/useActiveNavIds.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ function getActiveNavIds({
1212
const matches: { id: number; children: number[] }[] = []
1313

1414
for (const item of items) {
15-
if (item.link && path.startsWith(item.match || item.link))
15+
if (
16+
item.link &&
17+
(typeof item.match === 'function'
18+
? item.match(path)
19+
: path.startsWith(item.match || item.link))
20+
)
1621
matches.push({ id: item.id, children: [] })
1722
else if (item.items) {
1823
const activeChildItems = getActiveNavIds({ items: item.items, pathname })

src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ export type TopNavItem<parsed extends boolean = false> =
610610
}
611611
| ({
612612
element?: never
613-
match?: string
613+
match?: string | ((path: string) => boolean)
614614
text: string
615615
} & (
616616
| { link: string; items?: never }

0 commit comments

Comments
 (0)