Skip to content

@jsvision/ui / Route

Interface: Route<P>

Defined in: ui/src/router/types.ts:165

A route definition: how to build the screen for a set of params, plus optional keep-alive, focus, and (de)serialization behavior.

Example

ts
import { Group } from '@jsvision/ui';
import type { Route } from '@jsvision/ui';

class DetailScreen extends Group {
  constructor(readonly id: number) {
    super();
  }
}

const detail: Route<{ id: number }> = {
  build: (ctx) => ({ view: new DetailScreen(ctx.params.id) }),
  keepAlive: false,
  serialize: (p) => `id=${p.id}`,
  parse: (s) => ({ id: Number(new URLSearchParams(s).get('id')) }),
};

Type Parameters

P

P

Properties

build

build: (ctx) => ScreenBundle

Defined in: ui/src/router/types.ts:167

Build this route's screen bundle for the given params. Called on each activation unless kept alive.

Parameters

ctx

RouteContext<P>

Returns

ScreenBundle


focusKey?

optional focusKey?: (view) => string

Defined in: ui/src/router/types.ts:171

Optional exact-restore key: derive a stable key from the focused view so focus survives a rebuild.

Parameters

view

View

Returns

string


keepAlive?

optional keepAlive?: boolean

Defined in: ui/src/router/types.ts:169

Keep the screen mounted-but-hidden when navigating away, so its state survives a round-trip. Default off.


parse?

optional parse?: (s) => P

Defined in: ui/src/router/types.ts:175

Optional codec: parse this route's params back from a string.

Parameters

s

string

Returns

P


serialize?

optional serialize?: (params) => string

Defined in: ui/src/router/types.ts:173

Optional codec: serialize this route's params to a string (designed for deep-linking).

Parameters

params

P

Returns

string