Skip to main content
This is the first public alpha. APIs may change. Install better-router@alpha and pin the version you ship.
better-router is a fullstack Vite plugin. Files in src/routes become pages and API endpoints. Every request runs through Hono. Loader data is typed into React pages. The same tree can run on Node, Bun, Deno, or Cloudflare Workers. The source tree is the app. The plugin generates the server. You do not maintain a central router file.

What it gives you

File-based routing

Pages live in src/routes. _layout.tsx wraps nested UI. Companion .server.tsx files hold loaders and actions.

Hono on the server

Global middleware in src/middleware and nested _middleware.ts files use (c, next). API routes export GET / POST.

SSR, then SPA

The first load is HTML. <Link> navigations fetch JSON and swap the page. Island pages hydrate only the widgets you mark.

Cloudflare Workers

vite build emits a Worker with fetch. Bindings land on getEnv(). Optional scheduled, queue, and email handlers live in src/worker.ts.

Where things go

Routes and middleware are the only required folders. Add wrangler.jsonc when you deploy to Cloudflare.

Mental model

The plugin scans those files, generates a Hono app, and hydrates the client.

Install

vite.config.ts
Put pages in src/routes and middleware in src/middleware. Then run vite. Full walkthrough: Quickstart. For Workers, see Cloudflare.

Next steps

Quickstart

Add the plugin, a page, a loader, and an API route.

Cloudflare Workers

Build a Worker, point Wrangler at it, and deploy.

Bindings

Declare D1, KV, R2, and secrets in Wrangler. Read them with getEnv().

Worker entrypoint

defineWorker for fetch, cron, queues, and inbound email.