smolter
API

fileRouter

Configure flat route discovery and development server transport.

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/vite @kasperrt/smolter/preact/vite

Signature

const fileRouter: (options?: FileRouterOptions) => Plugin;

Parameters

directory defaults to src/routes. To use manual tables, provide both clientRoutes and serverRoutes paths relative to the Vite project.

Returns

A Vite plugin. fileRouter is an alias of routerPlugin.

Usage

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

import { fileRouter } from "@kasperrt/smolter/react/vite";

export default defineConfig({
  plugins: [fileRouter({ directory: "src/routes" })],
});

Behavior and edge cases

Requires Vite 8 or newer. Import virtual:smolter/routes for the generated table. Server loader/action exports must be named re-exports from separate files. Export-star and inline server handlers are rejected in browser route modules. The plugin handles development requests; production still needs a server adapter.

View implementation ↗