smolter
API

loadRouter

Load a server route before rendering.

Compatibility

ReactServer/build API, not a browser import.
React SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.
PreactServer/build API, not a browser import.
Preact SSRAvailable to this renderer's SSR integration; browser event handlers run after hydration.

Import from @kasperrt/smolter/react/server @kasperrt/smolter/preact/server

Signature

function loadRouter(
  routes: readonly Route[],
  input: string | Request,
): Promise<Router>;

Parameters

routes contains server route modules. input is an absolute URL string or a Request.

Returns

A Promise resolving to a request-scoped Router whose initial navigation has completed.

Usage

Import this API from one of the entry points listed above. Keep server and build helpers in their dedicated subpaths.

const router = await loadRouter(routes, request);
const snapshot = router.getSnapshot();

Behavior and edge cases

Server execution ignores clientLoader and clientAction. A Request forwards headers and combines its abort signal with router cancellation. Handle response status and redirects in your server adapter. Client-only loader routes produce a fallback snapshot for hydration.

View implementation ↗