modern-best-practice-nextjs
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNext.js Best Practices (App Router)
Next.js 最佳实践(App Router)
Next.js is a library that changes frequently - use web search or context7 MCP (via DocsExplorer agent) for exploring the current documentation.
Next.js是一个更新频繁的库——可通过网页搜索或context7 MCP(借助DocsExplorer agent)查阅最新文档。
Routing & Structure
路由与结构
- Use the App Router in for new work
app/ - Use nested layouts and route groups to organize sections
- Keep server components as the default; add only where needed
'use client'
- 新开发项目使用目录下的App Router
app/ - 使用嵌套布局和路由组来组织模块
- 默认使用Server Components;仅在必要时添加指令
'use client'
Data Fetching & Caching
数据获取与缓存
- Fetch data in React Server Components - AVOID fetching via and
useEffect()fetch() - Use server actions ("Server Functions") for mutations, potentially in conjunction with React Hooks like
useActionState
- 在React Server Components中获取数据——避免通过和
useEffect()获取数据fetch() - 使用Server Actions(“服务器函数”)处理数据变更,可结合等React Hooks使用
useActionState
UI States
UI状态
- Provide and
loading.tsxfor route-level UXerror.tsx - Use boundaries around async UI
Suspense
- 为路由级别的用户体验提供和
loading.tsx文件error.tsx - 在异步UI周围使用边界
Suspense
Metadata & SEO
元数据与SEO
- Use the Metadata API in layouts and pages
- Prefer static metadata when possible; keep dynamic metadata minimal
- 在布局和页面中使用Metadata API
- 尽可能优先使用静态元数据;尽量减少动态元数据的使用