Communitygithub.com

marnixGeerkens/rocketlauncher-claude-code

Next.js App Router 原理:服务端组件、数据获取、路由模式。

rocketlauncher-claude-code 是什么?

本技能系统性地整理了 Next.js App Router 开发的核心原则与最佳实践,适合希望在 Claude Code、Cursor 或 Codex 等 AI 编码助手中高效构建现代 React 应用的开发者。技能覆盖了从服务端/客户端组件决策、数据获取策略、路由组织、API 路由处理到性能优化与缓存机制的完整开发流程。通过清晰的决策树、对比表格和反模式指导,帮助开发者遵循「默认服务端组件」的推荐路径,仅在必要时引入客户端交互能力。该技能支持所有主流 AI 编码平台,其内容基于 Next.js 官方 App Router 文档提炼,可作为团队规范或个人开发的快速参考指南。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/marnixGeerkens/rocketlauncher-claude-code/tree/HEAD/components/skills/development/nextjs-best-practices

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Next.js 最佳实践

适用于 Next.js App Router 开发的原则。


1. 服务端组件 vs 客户端组件

决策树

是否需要……?
│
├── useState、useEffect、事件处理函数
│   └── 客户端组件('use client')
│
├── 直接数据获取,无需交互
│   └── 服务端组件(默认)
│
└── 两者都需要?
    └── 拆分:服务端父组件 + 客户端子组件

默认用法

类型用途
服务端数据获取、布局、静态内容
客户端表单、按钮、交互式 UI

2. 数据获取模式

获取策略

模式用途
默认静态(构建时缓存)
RevalidateISR(基于时间的刷新)
No-store动态(每次请求)

数据流向

来源模式
数据库服务端组件 fetch
API带缓存的 fetch
用户输入客户端状态 + 服务端操作

3. 路由原则

文件约定

文件用途
page.tsx路由 UI
layout.tsx共享布局
loading.tsx加载状态
error.tsx错误边界
not-found.tsx404 页面

路由组织

模式用途
路由组 (name)组织结构,不影响 URL
并行路由 @slot同级别多页面渲染
拦截路由 (.)模态框叠加

4. API 路由

路由处理器

方法用途
GET读取数据
POST创建数据
PUT/PATCH更新数据
DELETE删除数据

最佳实践

  • 使用 Zod 验证输入
  • 返回正确的状态码
  • 优雅地处理错误
  • 尽可能使用 Edge 运行时

5. 性能原则

图片优化

  • 使用 next/image 组件
  • 为首屏内容设置 priority
  • 提供模糊占位符
  • 使用响应式尺寸

包体积优化

  • 对重型组件使用动态导入
  • 基于路由的代码分割(自动)
  • 使用 bundle analyzer 分析

6. 元数据

静态 vs 动态

类型用途
静态导出固定元数据
generateMetadata每条路由动态生成

必要标签

  • title(50-60 字符)
  • description(150-160 字符)
  • Open Graph 图片
  • 规范 URL

7. 缓存策略

缓存层

层级控制方式
请求fetch 选项
数据revalidate / tags
完整路由路由配置

重新验证

方法用途
基于时间revalidate: 60
按需revalidatePath / revalidateTag
无缓存no-store

8. 服务端操作

使用场景

  • 表单提交
  • 数据变更
  • 触发重新验证

最佳实践

  • 使用 'use server' 标记
  • 验证所有输入
  • 返回类型化响应
  • 处理错误

9. 反模式

❌ 不要做✅ 推荐做法
到处使用 'use client'默认使用服务端组件
在客户端组件中 fetch在服务端组件中 fetch
忽略加载状态使用 loading.tsx
忽略错误边界使用 error.tsx
大型客户端包使用动态导入

10. 项目结构

app/
├── (marketing)/     # 路由组
│   └── page.tsx
├── (dashboard)/
│   ├── layout.tsx   # 仪表盘布局
│   └── page.tsx
├── api/
│   └── [resource]/
│       └── route.ts
└── components/
    └── ui/

记住: 服务端组件是默认选择,这是有原因的。先从服务端入手,仅在必要时添加客户端功能。

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

marnixGeerkens/rocketlauncher-claude-code

When the user wants to optimize, improve, or increase conversions on any marketing page — including homepage, landing pages, pricing pages, feature pages, or blog posts. Also use when the user says "CRO," "conversion rate optimization," "this page isn't converting," "improve conversions," or "why isn't this page working." For signup/registration flows, see signup-flow-cro. For post-signup activation, see onboarding-cro. For forms outside of signup, see form-cro. For popups/modals, see popup-cro.

marnixGeerkens/rocketlauncher-claude-code

Balance visual design with ATS compatibility for creative roles. Use when the user is in design, art, writing, marketing creative, or any visual/creative field and needs a resume that looks distinctive but still parses.

marnixGeerkens/rocketlauncher-claude-code

Transform resume bullets into detailed portfolio case studies with context, action, and outcome. Use when the user mentions portfolio, case study, project write-up, or expanding a resume bullet into a longer narrative.

marnixGeerkens/rocketlauncher-claude-code

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities. Use when: portfolio, personal website, showcase work, developer portfolio, designer portfolio.

marnixGeerkens/rocketlauncher-claude-code

Tailwind CSS v4 principles. CSS-first configuration, container queries, modern patterns, design token architecture.

marnixGeerkens/rocketlauncher-claude-code

Frontend development patterns for React, Next.js, state management, performance optimization, and UI best practices.

marnixGeerkens/rocketlauncher-claude-code

Frontend development guidelines for React/TypeScript applications. Modern patterns including Suspense, lazy loading, useSuspenseQuery, file organization with features directory, MUI v7 styling, TanStack Router, performance optimization, and TypeScript best practices. Use when creating components, pages, features, fetching data, styling, routing, or working with frontend code.

marnixGeerkens/rocketlauncher-claude-code

Expert integration of Supabase Auth with Next.js App Router Use when: supabase auth next, authentication next.js, login supabase, auth middleware, protected route.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

marnixGeerkens/rocketlauncher-claude-code

Create API handoff documentation for frontend developers. Use when backend work is complete and needs to be documented for frontend integration, or user says 'create handoff', 'document API', 'frontend handoff', or 'API documentation'.

marnixGeerkens/rocketlauncher-claude-code

Document frontend data needs for backend developers. Use when frontend needs to communicate API requirements to backend, or user says 'backend requirements', 'what data do I need', 'API requirements', or is describing data needs for a UI.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive Python library for astronomy and astrophysics. This skill should be used when working with astronomical data including celestial coordinates, physical units, FITS files, cosmological calculations, time systems, tables, world coordinate systems (WCS), and astronomical data analysis. Use when tasks involve coordinate transformations, unit conversions, FITS file manipulation, cosmological distance calculations, time scale conversions, or astronomical data processing.

marnixGeerkens/rocketlauncher-claude-code

Comprehensive patterns for Next.js 14+ App Router architecture, Server Components, and modern full-stack React development.

相关技能