Migrating from Next
These tables map the form and mutation features of Next 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.
| Next | Hamur | Differences |
|---|---|---|
"use server" at the top of a file or in a function | defineHandler exports of server/index.ts | there is no directive; a handler is a module-level export, and a closure over component variables is not supported |
<form action={serverAction}> | <Form action={fn}> | works without JavaScript; a plain <form action={fn}> calls the stub with JavaScript only |
useActionState(action, initial) | useAction(fn, { initial }) | state, failure, error, pending in all six libraries |
useFormStatus from react-dom | useFormStatus from @hamur/adapter-react | reads the Form it is in |
useOptimistic | React's useOptimistic, or useOptimistic from @hamur/adapter-react | Hamur's takes the running handler calls |
revalidatePath("/x") | refresh(event, fn, input) in the handler | primes the read the page makes next, so it sends nothing |
revalidateTag | none | |
redirect("/x") | redirect("/x") from hamur/app | return or throw it |
notFound() | throw createError({ status: 404 }) | |
cookies(), headers() | getCookie(event, …), getRequestHeader(event, …) | event is ctx.event |
| validate with Zod by hand | input: schema | any Standard Schema; 400 Validation failed with data.issues |
serverActions.bodySizeLimit | server.maxBodySize | default 1 MiB; a handler's form.maxBodySize replaces it for that handler |
serverActions.allowedOrigins | server.originCheck.allow | |
| a Server Action as a public endpoint | the same | authorize inside every handler; see Every handler is a public endpoint |
server-only package | server-only or hamur/server-only | the import guard fails the client build |
route handlers (route.ts) | a handler with a route | raw: true for a webhook or a raw body |
after() | none | |
| streaming a result from an action | return an AsyncIterable | the caller iterates with for await |
Rewrites, redirects and static params
next.config.js rewrites() and redirects() become routeRules; see Route rules. A has or missing list becomes when, and a rule with a condition is a list of entries.
import { defineConfig } from "hamur";
export default defineConfig({
framework: "react",
routeRules: {
"/docs/**": [{ when: { has: [{ type: "header", key: "x-beta" }] }, rewrite: "/guide/**" }],
"/old/:slug": { redirect: { to: "/new/:slug", status: 308 } },
"/promo": [{ when: { missing: [{ type: "cookie", key: "seen" }] }, redirect: { to: "/welcome", status: 307 } }],
},
});
| Next | Hamur | Differences |
|---|---|---|
rewrites(): { source, destination } | routeRules[source] = { rewrite: destination } | the destination is an app path; an outside URL is a proxy rule. :slug stays :slug and :path* is ** (or **:path), filled in the target as ** or :path |
redirects(): { source, destination } | routeRules[source] = { redirect: destination } or { redirect: { to, status } } | 307 unless you give a status |
permanent: true | status: 308 | there is no permanent key; { to, permanent: true } fails at load with routeRules["/a"].redirect has no key "permanent"; write status: 308 |
has, missing with type: "header", "cookie", "query" or "host" | when: { has, missing } on an entry of a list | value is a regular expression matched as a whole; a named group is a param for the target. An entry under when takes redirect, rewrite, proxy, headers, noindex, swr, cache and ssr |
| a large list of redirects | redirects: "redirects.json" | exact paths in a .json or .csv file, answered before the rules; see The redirects file |
NextResponse.rewrite(url) in middleware.ts | return rewrite(path) from a request step | a step of defineServer({ middleware }); see Server |
generateStaticParams() | export const entries in the page's x.load.ts | it returns one object of params per path. A file that exports generateStaticParams fails the scan: app/pages/blog/[slug].load.ts exports generateStaticParams; Hamur reads entries (07 §4.1). See Data |
export const dynamicParams = false | export const dynamicParams = false | beside entries, in the load file; a path that is not listed answers 404 |
Analog routeMeta: { redirectTo } | a redirect rule in routeRules, or meta.redirect on the page | meta.redirect becomes a rule under the page's path. With status: redirect: { to, status: 301 } |