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.
link Svelte action turns an ordinary <a> element into a client-side navigation trigger. Add use:link to any anchor inside your <Router> and the router will intercept eligible clicks, call navigate() internally, and update the history stack without a full-page reload. Per-anchor HTML attributes (replace, preserveScroll) let you customise each link’s behaviour without importing additional helpers.
Import
Usage
Supported attributes
The action reads the following HTML attributes directly from the<a> element at click time:
| Attribute | Type | Default | Description |
|---|---|---|---|
replace | boolean (presence) | false | Calls navigate with replace: true, replacing the current history entry instead of adding a new one |
preserveScroll | boolean (presence) | false | Calls navigate with preserveScroll: true, preventing the page from scrolling to the top after navigation |
Interception conditions
The action only intercepts a click when all of the following are true:anchor.targetis""(empty string) or"_self"— links that open in a new tab (target="_blank") are left to the browser.- The anchor’s host matches the current page’s host (same-origin only — external links pass through untouched).
- No keyboard modifier key was held (
Meta,Alt,Ctrl,Shift). Holding any modifier key preserves the browser’s default behaviour (e.g. open in new tab on macOS with ⌘-click). event.defaultPreventedisfalse— if another handler already prevented the event, the action steps aside.
event.preventDefault() is called and navigate(anchor.pathname + anchor.search, options) is invoked.
The
link action attaches a click listener to the element itself. If you need to apply routing to a large block of mixed anchors, consider use:links on a container element instead — it uses event delegation and avoids attaching a listener per anchor.Examples
Must be inside a Router
Thelink action calls navigate, which is the global navigate exported from svelte5-router. While navigate itself does not require a <Router> in scope, the route change will only be reflected in the UI if a <Router> ancestor exists to respond to history events. Always place use:link anchors within a <Router> tree.