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.
Route component registers itself with the nearest ancestor Router when it mounts, and renders its content only when the router decides it is the best match for the current URL. A Route can render in three ways: pass a component prop to mount a Svelte component constructor or a lazily-loaded dynamic import; use the children snippet to render inline markup that receives resolved URL parameters; or omit both path and component to create a default fallback route that activates when no other sibling Route matches. Extra props beyond path and component are forwarded directly to the rendered component.
Props
The URL pattern this route matches against. Segments prefixed with
: become named dynamic parameters (e.g. /blog/:id captures id). A bare * wildcard captures the remainder of the URL into a parameter named "*". A named wildcard such as *splatname captures the remainder into splatname. Omitting path (or passing an empty string) marks this route as the default/fallback route — it matches only when no other Route in the same Router produces a match.A Svelte component constructor to render when this route is active, or an
AsyncComponent produced by the dynamic() helper for code-split lazy loading. When component is provided, all resolved URL parameters and any extra props are spread onto it. If component is omitted, the children snippet is rendered instead.A Svelte 5 snippet rendered when the route is active and no
component prop is set. The snippet receives a single RouteParams argument — a record of all named URL parameters resolved from the matched path. Use the {#snippet children(params)} syntax to destructure and forward parameters to nested components.Any additional props passed to
<Route> are collected and spread onto the rendered component alongside the resolved URL parameters. This lets you pass static configuration values, event handlers, or data directly from the routing layer to a page component without an intermediate wrapper.TypeScript Types
RouteProps
RouteParams
A plain string-to-string map of all named URL parameters extracted from the matched path.
RouteLocation
Describes the current browser location, available through the useLocation hook and the Router children snippet.
AsyncComponent
The type returned by the dynamic() helper. It is a zero-argument function that returns a Promise resolving to a module with a default Svelte component export.
Route Scoring
Router automatically ranks all registered Route children so you never need to worry about declaration order. Each segment of a path contributes to a cumulative integer score:
| Segment type | Calculation |
|---|---|
| Per segment present | +4 |
Static literal (e.g. about) | +3 additional |
Dynamic parameter (e.g. :id) | +2 additional |
Splat wildcard (*) | −5 net (removes the +4 and adds a −1 penalty) |
Root path / | +1 |
Default route (path="") | Score = 0 — always last resort |
/blog/new(all static) beats/blog/:id(one dynamic segment)/blog/:idbeats/blog/*(splat)- Both beat the default
path=""fallback