import type { Unstable_Handlers as Handlers } from 'waku/minimal/server'; import type { BuildElementId, BuildPath } from './define-router-utils/build-handler.js'; import { getRequest, getRscParams, getRscPath, setNonce } from './define-router-utils/request-store.js'; import type { HandlerInterceptor } from './define-router-utils/request-store.js'; import type { Resolve, ResolveElement } from './define-router-utils/route-entries.js'; import type { NavigationHref } from './isomorphic-utils/build-route-href.js'; export { getRequest, getRscPath, getRscParams, setNonce }; export type { HandlerInterceptor }; /** * Requests a refresh of the calling route after the current server function * succeeds. Does not terminate execution or change the function's return value. * Repeated calls coalesce; redirect and not-found intents skip the refresh. * The route must render dynamically to read updated data. The client drops the * refresh if the user has left that route or any navigation is pending, while * keeping the function's return value. * Throws outside a Router server function or when its calling route is unknown. * * @example * const result = await saveChanges(); * requestRefresh(); * return result; */ export declare function requestRefresh(): void; /** * Schedules the calling route to render after the server function finishes, * unless a route intent was recorded. The client drops the rerender if the user * has left that route or any navigation is pending. * Only the last rerender requested by a server function is applied. * @deprecated Use `requestRefresh()`. Will be removed in a future release. */ export declare function rerenderRoute(): void; /** * Schedules a route to render after the current server function finishes. * A recorded route intent skips scheduled renders. `pathname` * is serialized as a URL pathname, so dot segments are resolved and unescaped * non-ASCII characters are percent-encoded. `query` is the search string * without `?`, serialized as URL search params, so `q=a b` becomes `q=a+b`. * Only the last rerender requested by a server function is applied. * @deprecated Use `requestRedirect()` to navigate. Will be removed in a future release. */ export declare function rerenderRoute(pathname: string, query?: string): void; /** * Requests the not-found view without terminating execution. Return from the * current component or server function after calling it. Before the document * response is returned this can produce HTTP 404; after the shell the client * shows the view. * The first intent recorded for a request wins, including concurrent renders. * A server function keeps its normal return value; a form submitted without * JavaScript responds with 404. * Use in dynamic renders, server functions, or handler interceptors before * `next()`. Immutable and prerendered sources must not record route intents. * API handlers return their own HTTP responses. Router does not apply intents * recorded inside them. * Ordinary rendering left in the response must eventually finish; discarded streams * are not guaranteed to be aborted. */ export declare function requestNotFound(): void; /** * @deprecated Use `requestNotFound()` and `cancelRender()` to control termination. * In handler interceptors, use `requestNotFound()` and return `next()`. * An uncaught cancellation there returns HTTP 204 or an empty RSC payload. */ export declare function notFound(): never; /** * Requests navigation without terminating execution. Return explicitly after * calling it. Accepts an app-relative path or an absolute HTTP(S) URL; validate * destinations derived from user input against your own allowlist. Before a * dynamic document response is returned this produces an HTTP redirect * (303 for a form POST). * After the shell, the browser follows the intent using JavaScript. * An absolute URL navigates the document even when it names this origin. * App-relative redirects must change the path or query. Use client navigation * for fragment-only changes. Ordinary rendering in the response must eventually * finish; discarded streams are not guaranteed to be aborted. * The first intent recorded for a request wins, including concurrent renders. * Use in dynamic renders, server functions, or handler interceptors before * `next()`. Immutable and prerendered sources must not record route intents. * API handlers return their own HTTP responses. Router does not apply intents * recorded inside them. */ export declare function requestRedirect(to: NavigationHref | `http://${string}` | `https://${string}` | URL, status?: 303 | 307 | 308): void; /** * @deprecated Use `requestRedirect()` and `cancelRender()` to control termination. * In handler interceptors, use `requestRedirect()` and return `next()`. * An uncaught cancellation there returns HTTP 204 or an empty RSC payload. */ export declare function redirect(to: NavigationHref | `http://${string}` | `https://${string}` | URL, status?: 303 | 307 | 308): never; type RouterOptions = { resolve: Resolve; getBuildPaths?: () => Promise>; getBuildElementIds?: () => Promise>; resolveElement?: ResolveElement; getHas404?: () => Promise; unstable_interceptors?: HandlerInterceptor[]; initialize?: () => Promise; getPrunableFiles?: () => Promise>; }; /** * Creates server handlers for `waku/router/client`. `resolve` receives the * normalized pathname and query string without `?`, and returns a router * definition with `root` and `route` element sources, an HTTP handler, or * `null` for not found. The document root uses `Children_UNSTABLE` to place * the active route. * * `getBuildPaths` lists pathnames to resolve, or explicit * `{ pathname, routerDefinition }` targets. Immutable routes are prerendered, * HTTP handlers emit static responses, and mutable routes cache only immutable * elements. A target's `prerender: false` caches immutable sources without * emitting a page; `prefetchRegExp` is a regular expression matching paths * that share its client modules. * `resolveElement` handles `slice:` requests from client `Slice` * components; `getBuildElementIds` lists immutable IDs to emit as standalone * RSC files, as strings to resolve or `{ id, source }` targets. * Only `slice:` IDs are supported for standalone requests. * Unresolved or mutable build IDs fail the build. * An immutable router definition source's optional `cacheKey` shares its * cached content across slot IDs. A route with only immutable sources can be * reused without a request, including in development. * Handler interceptors can be bypassed by static reuse; checks that must run * on each request require a dynamic route. * `createPages` and `fsRouter` supply route cache keys automatically. * Raw routers must supply `getHas404` to enable their custom 404 page. * The callback is queried when route metadata or a fallback needs availability; * `createPages` and `fsRouter` supply it from their route registry. * Immutable sources must render the same content for the lifetime of their ID * or explicit cache key. Use a bounded set of keys, not arbitrary request paths. * * A prerendered route or a built element ID is kept in the build output: at * runtime it is served from there for every request method, without asking * `resolve` or `resolveElement`. Immutable sources also render from the build * cache, so after the build `getPrunableFiles` lists source files that only * immutable sources use, for the server bundle to drop. `initialize` runs * before the first request or the build; after a failure, it runs again on * the next request. */ export declare function defineRouter(fns: RouterOptions): Handlers & { unstable_routerOptions: RouterOptions; }; /** * Combines routers created by `unstable_defineRouter`, `createPages`, or * `fsRouter` into one router. A route or an independently requested element, * such as a slice, belongs to the first router that resolves it. The build * fails when two routers list the same build path or element ID. * * The routers share element IDs, so an ID such as `root` or `layout:/` must * render the same content in every router that defines it. For example, give * `createPages` the root component that `fsRouter` reads from `_root.tsx`. * Handler interceptors from every router wrap every request, in router order. * If one router's `initialize` fails, the next request runs every router's * `initialize` again, so each must be safe to rerun; those of `createPages` * and `fsRouter` are. * * @example * export default adapter( * unstable_combineRouters( * createPages(async ({ createPage }) => [ * createPage({ path: '/company', render: 'static', component: Company }), * ]), * fsRouter(import.meta.glob('./pages/**\/*.{tsx,ts}')), * ), * ); */ export declare function combineRouters(...routers: ReturnType[]): ReturnType;