Next.js 最佳实践 - 文件约定、RSC 边界、数据模式、异步 API、元数据、错误处理、路由处理器、图像/字体优化、打包
在编写或审查 Next.js 代码时应用这些规则。
检测无效的 React 服务器组件模式。
Next.js 15+ 异步 API 变更。
params 和 searchParamscookies() 和 headers()参见 directives.md:
'use client'、'use server'(React)'use cache'(Next.js)参见 functions.md:
useRouter、usePathname、useSearchParams、useParamscookies、headers、draftMode、aftergenerateStaticParams、generateMetadataerror.tsx、global-error.tsx、not-found.tsxredirect、permanentRedirect、notFoundforbidden、unauthorized(认证错误)unstable_rethrow参见 data-patterns.md:
Promise.all、Suspense、预加载)route.ts 基础page.tsx 冲突参见 metadata.md:
generateMetadata 函数next/og 生成 OG 图像参见 image.md:
next/image 而非 <img>sizes 属性参见 font.md:
next/font 设置参见 bundling.md:
参见 scripts.md:
next/script vs 原生 script 标签id@next/third-parties 的 Google AnalyticsuseSearchParams 和 usePathname 的 CSR 降级@slot 和 (.) 拦截器的模态框模式default.tsxrouter.back() 正确关闭模态框参见 self-hosting.md:
output: 'standalone'参见 debug-tricks.md:
--debug-build-paths 重新构建特定路由