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.
navigate function lets you trigger route changes from JavaScript code — no <Link> component required. It is the go-to tool for redirecting users after form submissions, async operations such as authentication flows, or any logic-driven navigation that cannot be expressed declaratively. Under the hood, navigate is re-exported directly from the globalHistory singleton created by createHistory, so every call shares the same browser history session.
Import
Signature
Parameters
The destination path to navigate to, e.g.
"/dashboard" or "/blog/42?tab=comments". Must be a same-origin path; the function calls history.pushState or history.replaceState internally.When
true, the current history entry is replaced instead of a new entry being pushed. The user will not be able to press the browser back button to return to the page that called navigate. Useful for login redirects and post-submit flows where going back would re-trigger the action.An arbitrary serialisable object stored alongside the history entry via the Web History API. Accessible through
window.history.state or the useHistory / useLocation hooks. A key property (timestamp string) is merged in automatically by the router.When
true, the page will not scroll to the top after navigation. Useful for list→detail transitions where preserving scroll position improves UX.When
true, document.activeElement.blur() is called after navigation. Helpful for keyboard-driven UIs where focus should return to the document body after a navigation action.Return value
void
navigate returns nothing. Side effects are the history entry change and notifications to all registered listeners.How it works
navigate is the navigate method of globalHistory, a createHistory instance that wraps window.history (or a memory-based fallback in SSR / non-DOM environments). When called, it:
- Merges a timestamped
keyintostate. - Calls
window.history.pushStateorwindow.history.replaceStatedepending onreplace. - Updates the internal
locationsnapshot. - Notifies every registered listener with
{ location, action: "PUSH", preserveScroll }. - Optionally blurs the active element.
iOS Safari pushState limit — Safari on iOS caps
pushState calls at 100 per 30-second window. svelte5-router catches the resulting SecurityError and falls back to location.assign(to) (or location.replace(to) when replace is true), which causes a full-page navigation but keeps the app functional.push vs. replace
| Scenario | replace value | Effect |
|---|---|---|
| Normal link click | false (default) | New entry added; back button returns to previous page |
| Post-login redirect | true | Current entry replaced; back button skips the login page |
| Wizard step navigation | false | Each step is a history entry; back/forward works step-by-step |
| Error redirect | true | Avoids an unreachable “error” URL in history |