tuil
ReferencePackages

@mwillbanks/tuil-router

Typed terminal routes, guards, history, loaders, layouts, and focus restoration for tuil.

View rawEdit

Overview

Typed terminal routes, guards, history, loaders, layouts, and focus restoration for tuil.

@mwillbanks/tuil-router is independently installable and also participates in the umbrella @mwillbanks/tuil runtime where applicable.

Installation

npm install @mwillbanks/tuil-router

How it operates

The terminal router matches typed routes, executes guards and loaders, manages history and layouts, exposes navigation surfaces, and restores focus after transitions.

Documentation flow diagram. intent; match; before guards; loader; commit; focus restore; after hooks; S0 leads to S1
Documentation flow diagram. intent; match; before guards; loader; commit; focus restore; after hooks; S0 leads to S1

API

APISignatureDescription
createRouterfunction createRouterPublic function createRouter.
defineRoutesfunction defineRoutesPublic function defineRoutes.
FocusSnapshotinterface FocusSnapshotPublic interface FocusSnapshot.
NavigationEntryinterface NavigationEntryPublic interface NavigationEntry.
NavigationSurfacetype NavigationSurfacePublic type NavigationSurface.
NavigationTargettype NavigationTargetPublic type NavigationTarget.
routefunction routePublic function route.
RouteContextinterface RouteContextPublic interface RouteContext.
RouteDefinitioninterface RouteDefinitionPublic interface RouteDefinition.
RouteMatchinterface RouteMatchPublic interface RouteMatch.
RouterEventinterface RouterEventPublic interface RouterEvent.
RouterEventTypetype RouterEventTypePublic type RouterEventType.
RouterStateinterface RouterStatePublic interface RouterState.
TerminalRouterclass TerminalRouterPublic class TerminalRouter.
TerminalRouterOptionsinterface TerminalRouterOptionsPublic interface TerminalRouterOptions.

Events and lifecycle

router:navigation-start, router:navigation-complete, router:navigation-cancel, and router:navigation-error describe transition outcomes.

All subscriptions and registrations return a disposer or belong to an owning runtime that disposes them in reverse order.

Example

import { createRouter, defineRoutes, route } from "@mwillbanks/tuil-router";

const router = createRouter(defineRoutes({ home: route({ path: "/" }) }));
await router.navigate("home");

On this page