smolter
API

serverRoute

Build browser-safe proxies for server handlers.

Compatibility

ReactAvailable in this renderer's browser integration.
React SSRClient-side setup for an SSR application; do not execute on the server.
PreactAvailable in this renderer's browser integration.
Preact SSRClient-side setup for an SSR application; do not execute on the server.

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

Signature

function serverRoute<M extends RouteModule = RouteModule>(
  path: string,
  module: ClientRouteModule,
  handlers: ServerHandlers = { loader: true, action: true },
): Route<M>;

Parameters

path is the registered route pattern. module contains only browser-safe exports. handlers selects loader/action proxies; both default to true.

Returns

A typed Route with remote handlers and optional client call-through.

Usage

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

import { serverRoute } from "@kasperrt/smolter/react/client";
import Task from "./view";

const route = serverRoute<typeof import("./route")>(
  "/tasks/:id",
  { default: Task },
  { loader: true, action: true },
);

Behavior and edge cases

Requests append .__smolter to the actual route pathname, preserving queries and mutation bodies. /admin/users?page=2 becomes /admin/users.__smolter?page=2. Vite and Node adapters share normalization. Explicit handlers.dataEndpoint retains the legacy query transport and must match the host configuration. Set loader/action flags explicitly when supplying options. JSON transport resolves data before returning; runtime input validation and authorization remain application-owned.

serverRoute("/admin/users", browserModule, { loader: true, action: true });
View implementation ↗