/** Optional browser routing and data lifecycle, independent of the DOM renderer. */ import "./_dnt.polyfills.js"; export interface RouteContext { url: URL; params: Readonly>; signal: AbortSignal; } export interface ActionContext extends RouteContext { formData: FormData; method: 'POST' | 'PUT' | 'PATCH' | 'DELETE'; } export interface RouteModule { loader?: (context: RouteContext) => unknown | Promise; action?: (context: ActionContext) => unknown | Promise; view?: (state: RouterState) => Node | Node[]; } export interface Route extends RouteModule { /** Absolute path with :parameters or a final * wildcard. */ path: string; lazy?: () => Promise; } export interface RouteMatch { route: Route; params: Readonly>; } export interface RouterState { url: URL; match: RouteMatch | null; module: RouteModule | null; data: unknown; actionData: unknown; error: unknown; status: 'idle' | 'loading' | 'submitting'; } export declare class RouteError extends Error { status: number; data: unknown; constructor(status: number, data: unknown); } export declare class RouteRedirect { location: string; constructor(location: string); } /** Throw from a loader/action to navigate without committing its data. */ export declare function redirect(location: string): never; /** JSON transport for Go or any HTTP server; authorization stays on the server. */ export declare function fetchRouteData(input: string | URL, init?: RequestInit): Promise; /** Static segments win over parameters; parameters win over wildcards. */ export declare function matchRoute(routes: readonly Route[], pathname: string): RouteMatch | null; export interface RouterOptions { routes: readonly Route[]; /** Data serialized by the server for the initial URL. Omit to run its loader. */ initialData?: unknown; /** Cache is opt-in and bounded. Never cache across identities. */ staleTime?: number; cacheSize?: number; } export interface FetcherState { data: T | undefined; error: unknown; status: 'idle' | 'loading' | 'submitting'; } export interface FetcherSubmitOptions { /** Omit to invalidate all cached data; [] preserves all entries. */ invalidate?: readonly (string | URL)[]; } /** One router owns the window history. Call dispose() before replacing it. */ export declare function createRouter(options: RouterOptions): { readonly state: RouterState; ready: Promise; subscribe(listener: (state: RouterState) => void): () => void; navigate: (to: string | URL, settings?: { replace?: boolean; }) => Promise; createFetcher: () => { readonly state: FetcherState; subscribe(listener: (state: FetcherState) => void): () => void; load(to: string | URL): Promise; submit(to: string | URL, formData: FormData, method?: ActionContext["method"], settings?: FetcherSubmitOptions): Promise; dispose: () => void; }; submit(to: string | URL, formData: FormData, method?: ActionContext["method"]): Promise; revalidate(): Promise; invalidate: (urls?: readonly (string | URL)[]) => void; prefetch(to: string | URL): Promise; /** Opt-in link interception. Native modified/external/download clicks pass through. */ attach(target?: HTMLElement | Document): () => void; dispose(): void; };