Server routes.React pages.No API in between.
A route file holds a Hono handler and the React page it renders. Plain links and forms change pages in place: no API to write, no client-side router to keep in sync.
import { back, defineHandler, render } from 'fondu'
// GET /todos
export const loader = defineHandler(async (c) =>
render(c, Todos, { items: await db.todos.all() }),
)
// POST /todos, from the form
export const action = defineHandler.withValidator({ body: todo })(
async (c, { body }) => {
await db.todos.add(body)
return back(c)
},
)
// the page: all the browser gets of this file
export default function Todos({ items }: { items: Todo[] }) {
return (
<>
<ul>
{items.map((t) => (
<li key={t.id}>{t.text}</li>
))}
</ul>
<form method="post">
<input name="text" />
<button>Add</button>
</form>
</>
)
}Who does what
Three projects you may know already do most of the work, and their docs apply as they are; Fondu holds them together.
- HonoAnswers every request. Your routes are its handlers, with its middleware, CSRF protection and security headers.
- ReactRenders your page components and manages their state. React DOM renders the first page on the server and hydrates it in the browser.
- FonduHolds them together: routes from files, typed pages and URLs, the server render, the pages swapped in the browser.
- ViteServes the app while you work, updating it in place, and builds it for production.
What Fondu adds
The parts no one of them does, each a page of the docs.
Routes from files
The file path is the URL: params, optional segments, catch-alls, groups, and middleware and layouts for a directory.
Typed pages and URLs
render() checks the props a page takes, href() the params a URL needs, both typed from your files.
Forms and validation
Plain forms, one Standard Schema for the server and the browser. The errors land on the page, what was typed kept.
Server-side rendering
The first visit gets the page as HTML, then pages are swapped in place. Off for the pages that need none.
Static pages
A page that is the same for everyone can be written to a file at build time, and served with the same headers as the rest.
A URL per language
[[locale]] makes a segment optional, and a list of values keeps it to your languages.
Navigation without a router
Links and forms change the page in place, with view transitions, and a dialog can have its own URL.
Bun, Node or Workers
One vite build for Node and Bun; Cloudflare Workers through its own Vite plugin.
Start with one routeand one page.
The quick start creates an app for your runtime and walks through its first page.