[]previous and next page

createRouter

Creates a router.

Creates a router.

Nothing loads until Router.ready (or the RouterProvider, on the client) is called, so a server can await the first load before rendering. Each router owns its listeners and timers; Router.dispose removes them all.

Import#

ts
import { createRouter } from "@shadow-js/router";

Signature#

ts
function createRouter(options: RouterOptions): Router

Parameters#

Name Description
options Routes, features and policy. See RouterOptions.

Returns#

The router.

Throws#

  • Error when two routes match the same paths (the navigator's conflict report).
  • TypeError when two routes share an id, a feature is given twice, or a route uses an option whose feature is not given.

Examples#

ts
const router = createRouter({ routes: [home, posts], features: [scrollRestoration()] });
await router.ready();