nextjs-best-practices by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill nextjs-best-practicesNext.js App Router 开发原则。
Does it need...?
│
├── useState, useEffect, event handlers
│ └── Client Component ('use client')
│
├── Direct data fetching, no interactivity
│ └── Server Component (default)
│
└── Both?
└── Split: Server parent + Client child
| 类型 | 用途 |
|---|---|
| 服务器组件 | 数据获取、布局、静态内容 |
| 客户端组件 | 表单、按钮、交互式 UI |
| 模式 | 用途 |
|---|---|
| 默认 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 静态(构建时缓存) |
| 重新验证 | ISR(基于时间刷新) |
| 不存储 | 动态(每次请求) |
| 来源 | 模式 |
|---|---|
| 数据库 | 服务器组件 fetch |
| API | 带缓存的 fetch |
| 用户输入 | 客户端状态 + 服务器操作 |
| 文件 | 用途 |
|---|---|
page.tsx | 路由 UI |
layout.tsx | 共享布局 |
loading.tsx | 加载状态 |
error.tsx | 错误边界 |
not-found.tsx | 404 页面 |
| 模式 | 用途 |
|---|---|
路由组 (name) | 组织路由而不影响 URL |
并行路由 @slot | 多个同级页面 |
拦截路由 (.) | 模态叠加层 |
| 方法 | 用途 |
|---|---|
| GET | 读取数据 |
| POST | 创建数据 |
| PUT/PATCH | 更新数据 |
| DELETE | 删除数据 |
| 类型 | 用途 |
|---|---|
| 静态导出 | 固定元数据 |
| generateMetadata | 基于路由的动态元数据 |
| 层级 | 控制方式 |
|---|---|
| 请求 | fetch 选项 |
| 数据 | revalidate/标签 |
| 完整路由 | 路由配置 |
| 方法 | 用途 |
|---|---|
| 基于时间 | revalidate: 60 |
| 按需 | revalidatePath/Tag |
| 无缓存 | no-store |
| ❌ 避免 | ✅ 推荐 |
|---|---|
| 到处使用 'use client' | 默认使用服务器组件 |
| 在客户端组件中获取数据 | 在服务器端获取数据 |
| 跳过加载状态 | 使用 loading.tsx |
| 忽略错误边界 | 使用 error.tsx |
| 大型客户端包 | 使用动态导入 |
app/
├── (marketing)/ # Route group
│ └── page.tsx
├── (dashboard)/
│ ├── layout.tsx # Dashboard layout
│ └── page.tsx
├── api/
│ └── [resource]/
│ └── route.ts
└── components/
└── ui/
记住: 服务器组件是默认选择是有原因的。从那里开始,仅在需要时添加客户端组件。
每周安装量
338
代码仓库
GitHub 星标
22.6K
首次出现
2026年1月25日
安全审计
安装于
opencode257
codex250
gemini-cli243
github-copilot234
claude-code222
cursor210
Principles for Next.js App Router development.
Does it need...?
│
├── useState, useEffect, event handlers
│ └── Client Component ('use client')
│
├── Direct data fetching, no interactivity
│ └── Server Component (default)
│
└── Both?
└── Split: Server parent + Client child
| Type | Use |
|---|---|
| Server | Data fetching, layout, static content |
| Client | Forms, buttons, interactive UI |
| Pattern | Use |
|---|---|
| Default | Static (cached at build) |
| Revalidate | ISR (time-based refresh) |
| No-store | Dynamic (every request) |
| Source | Pattern |
|---|---|
| Database | Server Component fetch |
| API | fetch with caching |
| User input | Client state + server action |
| File | Purpose |
|---|---|
page.tsx | Route UI |
layout.tsx | Shared layout |
loading.tsx | Loading state |
error.tsx | Error boundary |
not-found.tsx | 404 page |
| Pattern | Use |
|---|---|
Route groups (name) | Organize without URL |
Parallel routes @slot | Multiple same-level pages |
Intercepting (.) | Modal overlays |
| Method | Use |
|---|---|
| GET | Read data |
| POST | Create data |
| PUT/PATCH | Update data |
| DELETE | Remove data |
| Type | Use |
|---|---|
| Static export | Fixed metadata |
| generateMetadata | Dynamic per-route |
| Layer | Control |
|---|---|
| Request | fetch options |
| Data | revalidate/tags |
| Full route | route config |
| Method | Use |
|---|---|
| Time-based | revalidate: 60 |
| On-demand | revalidatePath/Tag |
| No cache | no-store |
| ❌ Don't | ✅ Do |
|---|---|
| 'use client' everywhere | Server by default |
| Fetch in client components | Fetch in server |
| Skip loading states | Use loading.tsx |
| Ignore error boundaries | Use error.tsx |
| Large client bundles | Dynamic imports |
app/
├── (marketing)/ # Route group
│ └── page.tsx
├── (dashboard)/
│ ├── layout.tsx # Dashboard layout
│ └── page.tsx
├── api/
│ └── [resource]/
│ └── route.ts
└── components/
└── ui/
Remember: Server Components are the default for a reason. Start there, add client only when needed.
Weekly Installs
338
Repository
GitHub Stars
22.6K
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode257
codex250
gemini-cli243
github-copilot234
claude-code222
cursor210
Flutter应用架构设计指南:分层结构、数据层实现与最佳实践
3,000 周安装
Rust调用关系图生成器 - 可视化函数调用层次结构,提升代码分析效率
539 周安装
parallel-web-extract:并行网页内容提取工具,高效抓取网页数据
595 周安装
腾讯云CloudBase AI模型Web技能:前端调用混元/DeepSeek模型,实现流式文本生成
560 周安装
Apollo Connectors 模式助手:GraphQL API 连接器开发与集成指南
565 周安装
GitHub Trending 趋势分析工具:实时发现热门项目、技术洞察与开源机会
556 周安装
GSAP React 集成教程:useGSAP Hook 动画库与 React 组件开发指南
546 周安装