Skip to content

@jsvision/ui / createRouter

Function: createRouter()

createRouter<R>(opts): Router<R>

Defined in: ui/src/router/router.ts:410

Create a navigation / screen router — a full-screen screen stack that mounts as an application's content body. Typed by a Routes map ({ routeName: paramsType }), so navigation is param-safe.

Type Parameters

R

R

Parameters

opts

RouterOptions<R>

The initial route, the route table, and an optional logger.

Returns

Router<R>

A Router — pass it as createApplication({ content: router }) and drive it with push/back/replace/reset.

Example

ts
import { createApplication, createRouter } from '@jsvision/ui';

type Routes = { home: void; detail: { id: number } };

const router = createRouter<Routes>({
  initial: { name: 'home' },
  routes: {
    home: { build: () => ({ view: new HomeScreen() }) },
    detail: { build: (ctx) => ({ view: new DetailScreen(ctx.params.id) }) },
  },
});

const app = createApplication({ content: router });
router.push('detail', { id: 42 }); // typed against Routes