1. Install
better-router@alpha, hono, react, react-dom, and vite.
2. Enable the plugin
Replace the default Vite plugin list withbetterRouter(). It already includes @vitejs/plugin-react.
vite.config.ts
package.json
src/vite-env.d.ts
tsconfig.json
index.html and src/main.tsx. Pages live in src/routes, not a client entry.
Full compiler options are in TypeScript.
3. Layout and page
Layouts wrap the page tree. They do not render<html> or <body> — that is _document.tsx, or the default document the plugin already provides.
src/routes/_layout.tsx
src/routes/index.tsx
src/routes/index.server.tsx
useLoaderData(). Use whichever you prefer. The .server.tsx file never ships to the browser.
4. API route
src/routes/api/hello.ts
5. Run it
- App:
http://localhost:5173 - API:
http://localhost:5173/api/hello
<Link> fetch JSON and swap the page on the client.
vite build emits dist/client (assets) and dist/server (the Worker module). To deploy that to Cloudflare, see Cloudflare Workers.