Skip to content

Private previewMost of the architecture is written. First public release in 2027.

Migrating from Remix and React Router

These tables map the form and mutation features of Remix and React Router to Hamur. They cover forms and handlers only; the tables on pages, data and the server in Migrating from Nuxt apply to any app. none means Hamur has no equivalent today.

The shape is one thing in Hamur: a handler, a typed function that runs on the server, exported from server/index.ts. A form posts to it (Form action={fn}), a component calls it (useAction(fn), useAsyncData(fn, input)), and with a route a URL answers it. It works without JavaScript, it is a public endpoint that must check who calls it, and it needs no directive.

The route types (+types, href) and Vite's import.meta.env and modes are in Types and environment.

Remix, React RouterHamurDifferences
export async function action({ request }) in a routea handler exported from server/index.tsthe page posts to it with <Form action={fn}>
await request.formData()input of the handlerdecoded by formToObject
return data({ errors }, { status: 400 })return fail(400, { errors })
redirect("/x")redirect("/x")
<Form method="post" action reloadDocument replace><Form action={fn} reloadDocument replace>reset, instance, refresh and restore are added; Form posts through a handler or navigates with GET
useActionData()useAction(fn).state, .failure, .errorreadable anywhere in the app, not only in the route
useNavigation()useNavigation()state is idle or loading, plus revalidation; the fields of a running submission are in pendingRuns(app)
useFetcher() with fetcher.Form, submit, load, state, data, formDatauseAction(fn, { instance }) and <Form action={fn} instance={key}>a keyed run that does not navigate; useForm(fn).for(key) reads one
useFetchers()pendingRuns(app) from hamur/adapter
useSubmit()useAction(fn).run(input)a JSON call, not a form post
useRevalidator()useRouter().refresh() and useNavigation().revalidation
shouldRevalidate({ defaultShouldRevalidate })export const shouldRefresh in the pagedefaultShouldRefresh for defaultShouldRevalidate, plus currentUrl and nextUrl
optimistic UI from fetcher.formDatauseOptimistic(value, reduce)pending lists the running calls, each with its formData
a hidden intent field and a switch in actionone handler per intent
clientAction, clientLoadernonehandlers run on the server; browser-only data is useAsyncData(key, fn, { server: false })
unstable_parseMultipartFormDataform: { onFile }
resource routes (a route with a loader and no component)defineHandler({ route, raw: true })the loader becomes the handler, and it returns a Response or a value. See A resource route
loader and useLoaderDatauseAsyncData(fn, input), or x.load.ts and useData()load for a status decided before render
useFormActionnoneForm resolves its own action

A resource route

A route module that exports a loader and no component answers a URL with data or a file. In Hamur it is a handler with a route and raw: true. The request is event.request, the route params are read with getRouterParam(event, name), and a returned Response is sent as it is.

ts
import { defineHandler, getRouterParam } from "hamur/server";

export const reportCsv = defineHandler({
  route: "/reports/:id/export",
  method: "GET",
  raw: true,
  handler(_, { event }) {
    const id = getRouterParam(event, "id") as string;
    return new Response(`id,total\n${id},42\n`, { headers: { "content-type": "text/csv; charset=utf-8" } });
  },
});

The handler also answers POST or any other method when you set method, and method: "*" answers all of them. The route rules of the URL, such as headers or swr, apply to it like to any other path; see Route rules.