Skip to content
forma.
v3.2.0-rc.2
☰
Browse documentation
Start here
Application guides
API reference

Docs/API reference

FORMA 3.2

@getforma/router

Route matching, browser and native adapters, navigation, layouts, actions and lifecycle contracts.

View source ↗Markdown ↓Source 3b6c776
On this page

These guides target the 3.2.0-rc.2 release candidate. It is a prerelease; check the release record and qualify your application before rollout. Generated from the installed, version-pinned 3.2.0-rc.2 TypeScript declarations. Signatures, overloads and JSDoc are taken from the package; private class members are omitted. Declaration links point to version-pinned package files.

The router is optional. Use the same coordinated candidate as core, compiler, build and Rust. Keep one coordinator per document and retain ordinary document navigation outside the admitted profile.

Read the usage guide or all entry points.

28 exports · published 3.2.0-rc.2 declarations

ts
import { createBrowserAdapter } from '@getforma/router';

Values and functions

createBrowserAdapter#

Function export · Declaration, line 142

ts
declare function createBrowserAdapter(): RouteAdapter;

Each route render runs once inside a separately disposable Forma root.

Related declarations: RouteAdapter

createHtmlAdapter#

Function export · Declaration, line 166

ts
declare function createHtmlAdapter(options: HtmlAdapterOptions): RouteAdapter;

Explicitly registered static documents. Only the marked region is ever parsed.

Related declarations: HtmlAdapterOptions, RouteAdapter

createNativeAdapter#

Function export · Declaration, line 151

ts
declare function createNativeAdapter(bootstrap: NavigationBootstrap): RouteAdapter;

Related declarations: NavigationBootstrap, RouteAdapter

createRouter#

Function export · Declaration, line 135

ts
declare function createRouter(input: RouterOptions): Router;

One coordinator per Document. Private/native response cache capacity is deliberately zero.

Related declarations: Router, RouterOptions

defineRoutes#

Function export · Declaration, line 138

ts
declare function defineRoutes(input: readonly RouteDefinition[]): readonly RouteDefinition[];

Copy and validate caller configuration; mutation of the source never changes matching.

Related declarations: RouteDefinition

matchRoutes#

Function export · Declaration, line 139

ts
declare function matchRoutes(routes: readonly RouteDefinition[], pathname: string): readonly Match[] | null;

Related declarations: Match, RouteDefinition

NavigationError#

Class export · Declaration, line 127

ts
declare class NavigationError extends Error {
    readonly code: string;
    readonly documentRecovery: boolean;
    readonly revoke: boolean;
    constructor(code: string, documentRecovery?: boolean, revoke?: boolean);
}

Outlet#

Function export · Declaration, line 181

ts
declare function Outlet(props: {
    outlet: HTMLElement;
}): HTMLElement;

Return the exact child outlet supplied to a browser route render.

Exported types

Accessor#

Type alias export · Declaration, line 1

ts
type Accessor<T> = () => T;

ActionOutcome#

Interface export · Declaration, line 52

ts
interface ActionOutcome {
    readonly outcome: 'success' | 'validation' | 'error' | 'redirect';
    readonly status: number;
    readonly data: Readonly<Record<string, unknown>>;
}

AdapterSession#

Interface export · Declaration, line 57

ts
interface AdapterSession {
    initialize?(context: NavigationContext): Promise<void>;
    prepare(context: NavigationContext): Promise<PreparedView | Redirect>;
    allowsAction?(url: URL): boolean;
    admitAction?(data: unknown, response: Response, url: URL): ActionOutcome;
    invalidate?(): void;
    dispose(): void;
}

Related declarations: ActionOutcome, NavigationContext, PreparedView, Redirect

HtmlAdapterOptions#

Interface export · Declaration, line 161

ts
interface HtmlAdapterOptions {
    readonly head: string;
    readonly pages: readonly HtmlPage[];
}

Related declarations: HtmlPage

HtmlPage#

Interface export · Declaration, line 153

ts
interface HtmlPage {
    readonly path: string;
    readonly sha256: string;
    readonly title: string;
    readonly head: string;
}

Member notes

sha256

SHA-256 of the complete UTF-8 generated document, emitted at build time.

head

Build-generated identity of the immutable head/policy/assets.

LinkProps#

Interface export · Declaration, line 168

ts
interface LinkProps {
    href: string | URL;
    children?: string | Node | readonly (string | Node)[];
    target?: string;
    download?: string;
    class?: string;
    native?: boolean;
    document?: Document;
}

Member notes

native

Leave this link to the browser.

LocationState#

Interface export · Declaration, line 16

ts
interface LocationState {
    readonly url: URL;
    readonly key: string;
    readonly matches: readonly {
        readonly id: string;
        readonly params: Readonly<Record<string, string>>;
    }[];
}

Match#

Interface export · Declaration, line 11

ts
interface Match {
    readonly id: string;
    readonly params: Readonly<Record<string, string>>;
    readonly definition: RouteDefinition;
}

Related declarations: RouteDefinition

NavigationBootstrap#

Interface export · Declaration, line 144

ts
interface NavigationBootstrap {
    readonly registrations: Readonly<Record<string, (element: HTMLElement, props: Record<string, unknown> | null) => unknown>>;
    readonly app: string;
    readonly build: string;
    readonly group: string;
    readonly owners: readonly string[];
}

NavigationContext#

Interface export · Declaration, line 33

ts
interface NavigationContext {
    readonly url: URL;
    readonly matches: readonly Match[];
    readonly signal: AbortSignal;
    readonly revalidate: boolean;
    readonly location: Accessor<LocationState>;
}

Related declarations: Accessor, LocationState, Match

NavigationResult#

Type alias export · Declaration, line 85

ts
type NavigationResult = {
    kind: 'committed';
    location: LocationState;
    ready: Promise<void>;
} | {
    kind: 'cancelled';
    reason: 'superseded' | 'unchanged' | 'disposed';
} | {
    kind: 'blocked';
} | {
    kind: 'document-navigation';
    reason: string;
} | {
    kind: 'failed';
    code: string;
};

Related declarations: LocationState

PreparedView#

Interface export · Declaration, line 40

ts
interface PreparedView {
    readonly title?: string;
    readonly status?: number;
    readonly focus?: HTMLElement;
    validate(): void;
    commit(): void;
    activate(): Promise<void>;
    dispose(): void;
}

Redirect#

Interface export · Declaration, line 49

ts
interface Redirect {
    readonly redirect: string;
}

RenderContext#

Interface export · Declaration, line 24

ts
interface RenderContext {
    readonly url: URL;
    readonly location: Accessor<LocationState>;
    readonly params: Readonly<Record<string, string>>;
    readonly outlet: HTMLElement;
    readonly signal: AbortSignal;
}

Related declarations: Accessor, LocationState

Member notes

url

Destination snapshot for one-time route initialization.

signal

Aborts if preparation is cancelled or this owner is released; retained owners stay live.

RouteAdapter#

Interface export · Declaration, line 65

ts
interface RouteAdapter {
    readonly kind: 'browser' | 'html' | 'native';
    connect(root: HTMLElement): AdapterSession;
}

Related declarations: AdapterSession

RouteDefinition#

Interface export · Declaration, line 2

ts
interface RouteDefinition {
    readonly id: string;
    readonly path?: string;
    readonly index?: true;
    readonly children?: readonly RouteDefinition[];
    readonly adapter?: RouteAdapter;
    readonly render?: (context: RenderContext) => Element;
    readonly reuseKey?: (context: Match) => string;
}

Related declarations: Match, RenderContext, RouteAdapter

Router#

Interface export · Declaration, line 110

ts
interface Router {
    readonly location: Accessor<LocationState>;
    readonly pending: Accessor<URL | undefined>;
    readonly mutation: Accessor<'idle' | 'submitting' | 'revalidating' | 'uncertain'>;
    readonly ready: Promise<void>;
    navigate(to: string | URL, options?: {
        replace?: boolean;
    }): Promise<NavigationResult>;
    revalidate(): Promise<NavigationResult>;
    prefetch(to: string | URL): Promise<'completed' | 'skipped' | 'cancelled'>;
    submit(form: HTMLFormElement, submitter?: HTMLElement): Promise<SubmissionResult>;
    beforeLeave(check: (next: URL, signal: AbortSignal) => boolean | Promise<boolean>): () => void;
    invalidateContext(): void;
    resolveUncertain(check: (signal: AbortSignal) => Promise<boolean>): Promise<boolean>;
    dispose(): void;
}

Related declarations: Accessor, LocationState, NavigationResult, SubmissionResult

Member notes

resolveUncertain

Clear the unknown-outcome latch only after application status/idempotency evidence.

RouterOptions#

Interface export · Declaration, line 69

ts
interface RouterOptions {
    readonly routes: readonly RouteDefinition[];
    readonly root: HTMLElement;
    readonly adapter: RouteAdapter;
    readonly base?: string;
    readonly statusRegion?: HTMLElement;
    readonly title?: (location: LocationState) => string;
    readonly onError?: (code: string) => void;
    readonly onAction?: (outcome: ActionOutcome, form: HTMLFormElement) => void;
    readonly checkContext?: (signal: AbortSignal) => Promise<boolean>;
    readonly contextChannel?: string;
    readonly recoveryKey?: string;
    readonly canPrefetch?: (url: URL) => boolean;
}

Related declarations: ActionOutcome, LocationState, RouteAdapter, RouteDefinition

Member notes

recoveryKey

Public, build-specific recovery namespace. Never put a user identifier here.

canPrefetch

Explicit server/application attestation that this GET is safe to speculate.

SubmissionResult#

Type alias export · Declaration, line 101

ts
type SubmissionResult = {
    kind: 'success';
} | {
    kind: 'validation' | 'error';
    status: number;
    data: Readonly<Record<string, unknown>>;
} | {
    kind: 'busy' | 'unsupported' | 'uncertain' | 'disposed';
};

Find your next answer.

Search versioned Forma documentation, guides and examples.