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
import { createBrowserAdapter } from '@getforma/router';Values and functions
createBrowserAdapter#
declare function createBrowserAdapter(): RouteAdapter;Each route render runs once inside a separately disposable Forma root.
Related declarations: RouteAdapter
createHtmlAdapter#
declare function createHtmlAdapter(options: HtmlAdapterOptions): RouteAdapter;Explicitly registered static documents. Only the marked region is ever parsed.
Related declarations: HtmlAdapterOptions, RouteAdapter
createNativeAdapter#
declare function createNativeAdapter(bootstrap: NavigationBootstrap): RouteAdapter;Related declarations: NavigationBootstrap, RouteAdapter
createRouter#
declare function createRouter(input: RouterOptions): Router;One coordinator per Document. Private/native response cache capacity is deliberately zero.
Related declarations: Router, RouterOptions
defineRoutes#
declare function defineRoutes(input: readonly RouteDefinition[]): readonly RouteDefinition[];Copy and validate caller configuration; mutation of the source never changes matching.
Related declarations: RouteDefinition
Link#
declare function Link(props: LinkProps): HTMLAnchorElement;An ordinary anchor; interception belongs to the root coordinator.
Related declarations: LinkProps
matchRoutes#
declare function matchRoutes(routes: readonly RouteDefinition[], pathname: string): readonly Match[] | null;Related declarations: Match, RouteDefinition
Outlet#
declare function Outlet(props: {
outlet: HTMLElement;
}): HTMLElement;Return the exact child outlet supplied to a browser route render.
Exported types
Accessor#
type Accessor<T> = () => T;ActionOutcome#
interface ActionOutcome {
readonly outcome: 'success' | 'validation' | 'error' | 'redirect';
readonly status: number;
readonly data: Readonly<Record<string, unknown>>;
}AdapterSession#
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 HtmlAdapterOptions {
readonly head: string;
readonly pages: readonly HtmlPage[];
}Related declarations: HtmlPage
HtmlPage#
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 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 LocationState {
readonly url: URL;
readonly key: string;
readonly matches: readonly {
readonly id: string;
readonly params: Readonly<Record<string, string>>;
}[];
}Match#
interface Match {
readonly id: string;
readonly params: Readonly<Record<string, string>>;
readonly definition: RouteDefinition;
}Related declarations: RouteDefinition
PreparedView#
interface PreparedView {
readonly title?: string;
readonly status?: number;
readonly focus?: HTMLElement;
validate(): void;
commit(): void;
activate(): Promise<void>;
dispose(): void;
}Redirect#
interface Redirect {
readonly redirect: string;
}RenderContext#
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 RouteAdapter {
readonly kind: 'browser' | 'html' | 'native';
connect(root: HTMLElement): AdapterSession;
}Related declarations: AdapterSession
RouteDefinition#
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 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 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 SubmissionResult = {
kind: 'success';
} | {
kind: 'validation' | 'error';
status: number;
data: Readonly<Record<string, unknown>>;
} | {
kind: 'busy' | 'unsupported' | 'uncertain' | 'disposed';
};