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 component renders a standard HTML <a> element that performs client-side navigation without a full page reload. It resolves the to destination relative to the nearest Router base URI, listens for clicks, and calls the router’s navigate function instead of following the browser’s default anchor behaviour. Link automatically detects whether the rendered href matches the current pathname and sets aria-current="page" for accessibility. Because Link extends HTMLAnchorAttributes, every standard anchor attribute (class, id, data-*, etc.) is accepted and forwarded to the underlying <a> element.
Props
The destination URL. Absolute paths (starting with
/) are used as-is. Relative paths are resolved against the nearest Router base URI using the same directory-style resolution that cd uses on a filesystem — every path is treated as a directory, never a file. If to is omitted entirely the link defaults to "#".When
true, clicking the link calls history.replaceState instead of history.pushState, so the current URL is overwritten rather than a new entry being added. The router also implicitly replaces instead of pushing when the destination matches the current pathname, preventing duplicate history entries.An arbitrary serialisable object attached to the new history entry. Retrieve it later via
useLocation() as location.state. Useful for passing ephemeral data between routes without exposing it in the URL.When
true, the router will not call window.scrollTo(0, 0) after navigating to the linked route. Use this for in-page navigation (tabs, modals, anchor-linked sections) where restoring the scroll position to the top would be disorienting.An optional click-event handler called before the router’s own click logic. The handler receives the native
MouseEvent. If you call event.preventDefault() inside this handler, the router will still inspect defaultPrevented and skip navigation accordingly.Content rendered inside the
<a> element. The snippet receives a single boolean argument — true when the link’s href exactly matches the current pathname (isCurrent), false otherwise. Use this to conditionally apply active styles or swap child components.Deprecated. This prop is no longer applied to the rendered anchor element. The implementation still accepts the prop to avoid breaking existing code, but the returned object is currently ignored. Use the
children active-state boolean or standard HTML attributes instead.<a> element. It received a GetPropsParams object with location, href, isPartiallyCurrent, and isCurrent fields.All remaining props are spread directly onto the underlying
<a> element via Svelte’s rest-props mechanism. This includes class, id, style, target, rel, data-* attributes, and any other valid HTML anchor attribute — except href, which is always computed from to.TypeScript Types
LinkProps
GetPropsParams
Passed to the deprecated getProps callback. Documented here for completeness.
aria-current Behaviour
Link sets aria-current="page" on the rendered <a> element whenever the resolved href exactly equals location.pathname. When the link is not current the attribute is omitted entirely (set to undefined). This keeps the DOM clean and works correctly with screen readers and CSS attribute selectors: