Repository navigation
feat(pages): mark the Link to the current page - #687
Merged
Merged
Conversation
`Link` renders `aria-current="page"` and `data-void-active` when it points to the current page, in all four adapters. `activeMatch="prefix"` keeps a link active on nested pages; only an exact match gets `aria-current`. Matching lives in `linkActiveAttributes` in `void/pages-client` and follows the router: pathnames compare case-sensitively with trailing slashes significant, the query and hash are ignored, and links to other origins or with non-GET methods never match. A passed `aria-current` or `data-void-active` overrides the computed value. Closes voidzero-dev#676 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #676. Implements the proposal in the issue.
What this adds
Linkmarks the link to the current page witharia-current="page"anddata-void-active, in React, Vue, Svelte and Solid. Navigation menus no longer need to compareuseRouter().pathwith eachhrefby hand, and the current link getsaria-currentby default.activeMatch?: 'exact' | 'prefix', default'exact'.prefixkeeps a link active on nested pages.data-void-activeon any match,aria-current="page"on an exact match only. On/users/42, the Users link above getsdata-void-activebut notaria-current.aria-currentordata-void-activepassed toLinkreplaces the computed value.Matching rules
/usersmatches/users/42, not/users-admin./only matches itself/Adminand/admin/don't match/adminThe two open questions from the issue are settled to follow the router, which treats
/admin/and/Adminas different pages from/admin.Implementation
linkActiveAttributes(router, link, match)invoid/pages-clientdoes the matching and returns the attributes, so the names, values and default can't drift between adapters. Each adapter passes its router (which changes with the route URL), spreads the result before the user's attributes, and passesactiveMatchthrough without its own default.The server-side router already carries the request URL, so the attributes are in the server HTML and hydration doesn't change them. Island pages have no Void Router and render
Linkwithout active state; the islands guide already says to use plain<a>there.Docs
docs/guide/pages-routing/overview.md): new "Active links" section with adapter examples and a matching table.activeMatchand the two attributes on each adapter'sLink.voidskill: a working rule pointing agents at the attributes instead of hand-writtenuseRouter().pathchecks.Test plan
linkActiveAttributesunit tests: exact and prefix matching,/, whole segments, query and hash, letter case, trailing slashes, encoding, relative and absolute hrefs, other origins, non-GET links, no routerLinkunit tests: server markup, prefix, overrides, no routeractiveMatchaccepts only'exact' | 'prefix'activeMatch="prefix"vp run check: 33/33vp test run: 763/771 files passed under full load; the 7 failing files (Nuxt, SSR, TanStack Start, WebSocket playgrounds, a DB template test, a Sandbox runner test, a Cloudflare v2 test) all pass when rerun on their own🤖 Generated with Claude Code