TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jpcutshall/svelte5-router/llms.txt
Use this file to discover all available pages before exploring further.
links Svelte action is the bulk alternative to use:link. Instead of decorating every individual anchor, you apply use:links once to a parent element and it captures all relative anchor clicks inside that subtree through event delegation. This is ideal for application shells, CMS-rendered HTML, or any layout where individual anchors are dynamic and cannot easily be decorated one by one.
Import
Usage
Supported anchor attributes
Each individual<a> element inside the container can carry these attributes to customise its navigation behaviour:
| Attribute | Type | Default | Description |
|---|---|---|---|
replace | boolean (presence) | false | Passes replace: true to navigate, replacing the current history entry |
preserveScroll | boolean (presence) | false | Passes preserveScroll: true to navigate, keeping the current scroll position |
noroute | boolean (presence) | false | Opts this anchor out of the action entirely. The click is not intercepted and the browser handles it natively |
How it works
The action attaches a singleclick listener to the container. On each click it:
- Walks up the DOM from
event.targetby traversingparentElementuntil it finds an element whosetagNameis"A"(equivalent to aclosest("A")walk, but implemented manually for broader compatibility). - Checks the same interception conditions as
use:link(same-origin, no modifier keys,targetis""or"_self",event.defaultPreventedisfalse). - Additionally checks that the anchor does not have the
norouteattribute. - If all checks pass, calls
event.preventDefault()andnavigate(anchor.pathname + anchor.search, options).
Because the action uses event delegation, anchors added to the container after the initial render are still intercepted automatically — no re-mounting or re-applying the action is required.
Examples
links vs. link — which to use?
| Concern | use:link (on <a>) | use:links (on container) |
|---|---|---|
| Attachment point | Individual <a> tag | Parent / wrapper element |
| Event listeners | One per anchor | One per container (event delegation) |
| Dynamic anchors | Must apply use:link to each new anchor | Automatically covered |
| Opt-out | N/A — remove use:link | Add noroute attribute to the anchor |
| Best for | A handful of known, static links | Navigation sections, CMS content, generated link lists |