diff --git a/docs/guide/pages-routing/overview.md b/docs/guide/pages-routing/overview.md index 08ad304eb..004b9a3ef 100644 --- a/docs/guide/pages-routing/overview.md +++ b/docs/guide/pages-routing/overview.md @@ -265,6 +265,65 @@ export default function PostPage() { } ``` +### Active links + +`Link` marks the link to the current page with `aria-current="page"` and `data-void-active`. Use them to style navigation: + +```css +nav a[data-void-active] { + font-weight: 600; +} +``` + +A link is active only on its own path by default. Set `activeMatch="prefix"` to keep it active on nested pages: + +::: code-group + +```tsx [React] + +``` + +```vue [Vue] + +``` + +```svelte [Svelte] + +``` + +```tsx [Solid] + +``` + +::: + +| Current URL | `href="/users"` | `href="/users" activeMatch="prefix"` | +| --------------- | --------------- | ------------------------------------ | +| `/users` | both attributes | both attributes | +| `/users?page=2` | both attributes | both attributes | +| `/users/42` | none | `data-void-active` | +| `/users-admin` | none | none | + +`aria-current="page"` marks only the exact page, so select `[aria-current="page"]` to style it differently from its section. A link to `/` is active only on the home page. + +Paths match the way pages are routed: letter case and trailing slashes count, while the query string and hash are ignored. Links to other origins and non-GET links are never active. An `aria-current` or `data-void-active` you pass to `Link` replaces the computed value. + ## Scroll Restoration Void manages scroll position for Pages automatically: diff --git a/docs/reference/api/pages.md b/docs/reference/api/pages.md index b577e75ee..dd10cd0fd 100644 --- a/docs/reference/api/pages.md +++ b/docs/reference/api/pages.md @@ -53,16 +53,16 @@ interface VoidVueOptions { Imported from `"@void/vue"`. -| Export | Description | -| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `Link` | Vue component for SPA navigation. Renders `` for GET, `