Skip to content

@isorouter/svelte

Svelte 5 adapter. Requires Svelte ≥ 5.7. For a walkthrough see the Svelte guide.

sh
npm install @isorouter/svelte

Exports

ExportKindDescription
createRouterfunctioncreateCoreRouter with the component type fixed to Svelte's Component; returns a SvelteRouter.
SvelteRouterclassThe reactive wrapper around the core router.
RoutercomponentRoot component — calls start/stop, renders matched component or loading/notFound/error snippets.
OutletcomponentRenders the next component in the matched chain; nothing if no child.
LinkcomponentA plain <a> intercepted by the Navigation API.
getRouterfunctionReads the SvelteRouter from context (within <Router>/<Outlet>).
lazyfunctionRe-exported from @isorouter/core.

Types

AnySvelteRouter, SvelteComponentType, Register, RegisteredRouter, plus the core re-exports BeforeLoad, GuardContext, Href, NavTarget, RouteConfig, RouterOptions, RouterSnapshot.

Augment Register to narrow getRouter() to the concrete router type — see Type-safe navigation.

<Router> snippets

SnippetShown when
loadingno matched root component yet, and neither error nor notFound applies.
notFoundrouter.current.status === "not-found".
error(err)router.current.status === "error" — receives router.current.error.

href, class (merged with activeClass), activeClass (default "active"), exact. Sets aria-current="page" when active. Other attributes forwarded to the <a>. See Links & active state.

getRouter()

Returns the RegisteredRouter (resolves to the concrete SvelteRouter<T> when Register is augmented, or AnySvelteRouter otherwise). router.current is a getter — read it inside a $derived, $effect or the template to subscribe to commits; the subscription drops once nothing reads it. router.navigate, router.back, router.forward and router.isActive are available on the instance too.

Bridge primitive: Svelte 5's createSubscriber — the subscription is live only while current is read in a reactive scope, and is auto-torn-down.

Released under the MIT License.