Next.js 服务端渲染笔记
Next.js 服务端渲染笔记
读取请求信息
在服务端组件里用 headers() 读取请求头:
import { headers } from "next/headers";
const host = (await headers()).get("host") ?? "";
Server Actions
表单可以直接提交到 Server Action,无需额外接口:
<form action={savePostAction}>
<input name="title" />
<button type="submit">保存</button>
</form>
注意事项
- 需要读 Host 的页面导出
dynamic = "force-dynamic" - 原生模块(如 better-sqlite3)加入
serverExternalPackages
评论(0)
还没有评论,来抢沙发。