openclaw-skills/nextjs-app-router/SKILL.md
用于 Next.js App Router 模式开发,包含 RSC、Server Actions 和路由最佳实践。来源:skills.sh 10.2K installs。
npx skillsauth add seaworld008/commonly-used-high-value-skills nextjs-app-routerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
app/ 目录下默认所有组件为 Server Components,而 pages/ 默认为 Client Components。layout.tsx 实现跨页面状态保持和 UI 共享,避免不必要的重新渲染。async/await 调用数据库(如 Prisma, Drizzle)或第三方 API,无需外部数据获取 Hook(如 SWR/React Query)。"use client") 和 Server Component。尽可能将状态、事件处理器和浏览器 API(如 useEffect, window)封装在小的 Client Component 中,保持大块 UI 为 Server Component 以减少 JS Bundle 体积。action 属性绑定 Server Action,结合 useFormStatus 和 useFormState 处理 Loading 状态和验证反馈。auth()) 和权限校验。revalidatePath("/") 或 revalidateTag("collection") 触发局部数据缓存刷新。@folder 语法在同一布局中同时显示多个独立页面(如仪表盘中同时展示统计表和通知列表)。(..) 语法在当前上下文拦截路由(如点击图片在 Modal 中预览,但刷新页面则直接导航至详情页)。[id]、[[...slug]] (Catch-all) 进行动态路径匹配。loading.tsx 实现即时的骨架屏反馈。<Suspense> 包裹耗时的数据拉取组件,允许页面的非阻塞加载,优先显示已就绪的静态内容。layout.tsx 或 page.tsx 中定义 export const metadata 对象。generateMetadata 函数基于路由参数或数据动态生成页面标题、描述和 OpenGraph 图像。config.matcher 中精确定义中间件执行的路径范围。# 启动本地开发服务 (带热更新)
pnpm dev
# 构建生产产物并分析体积 (Next.js Bundle Analyzer)
ANALYZE=true pnpm build
# 快速检查当前路由配置
find app/ -name "page.tsx" -o -name "route.ts" | sort
# 检查 Next.js 版本并升级
pnpm outdated next
pnpm add next@latest react@latest react-dom@latest
// app/users/[id]/page.tsx
import { db } from "@/lib/db";
import { Suspense } from "react";
import UserSkeleton from "@/components/UserSkeleton";
async function UserProfile({ id }: { id: string }) {
const user = await db.user.findUnique({ where: { id } });
if (!user) return <div>User not found</div>;
return <h1>{user.name}</h1>;
}
export default function Page({ params }: { params: { id: string } }) {
return (
<main>
<Suspense fallback={<UserSkeleton />}>
<UserProfile id={params.id} />
</Suspense>
</main>
);
}
// actions/user-actions.ts
"use server";
import { revalidatePath } from "next/cache";
export async function updateUsername(formData: FormData) {
const name = formData.get("username") as string;
// 1. 权限校验 (例如使用 next-auth)
// 2. 数据库更新 (例如 Prisma)
await db.user.update({ data: { name } });
// 3. 刷新缓存并重定向
revalidatePath("/profile");
}
// middleware.ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const token = request.cookies.get('next-auth.session-token');
if (!token && request.nextUrl.pathname.startsWith('/dashboard')) {
return NextResponse.redirect(new URL('/login', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/dashboard/:path*', '/settings/:path*'],
};
fs, pg),必须通过 Props 传递数据。use server)。force-dynamic 等配置。"use client" 或使用 Wrapper。testing
Orchestrating specialist AI agent teams as a meta-coordinator. Decomposes requests into minimum viable chains, spawns each as an independent session in AUTORUN modes, and drives to final output. Use when a task spans multiple specialist domains, requires parallel agent execution, or needs hub-and-spoke routing across the skill ecosystem.
tools
Deploy web projects to Netlify using the Netlify CLI (`npx netlify`). Use when the user asks to deploy, host, publish, or link a site/repo on Netlify, including preview and production deploys.
tools
Guides and best practices for working with Neon Serverless Postgres. Covers setup, connection methods, branching, autoscaling, scale-to-zero, read replicas, connection pooling, Neon Auth, and the Neon CLI, MCP server, REST API, TypeScript SDK, and Python SDK. Use when users ask about "Neon setup", "connect to Neon", "Neon project", "DATABASE_URL", "serverless Postgres", "Neon CLI", "neonctl", "Neon MCP", "Neon Auth", "@neondatabase/serverless", "@neondatabase/neon-js", "scale to zero", "Neon autoscaling", "Neon read replica", or "Neon connection pooling".
tools
Built-in MCP (Model Context Protocol) client that connects to external MCP servers, discovers their tools, and registers them as native Hermes Agent tools. Supports stdio and HTTP transports with automatic reconnection, security filtering, and zero-config tool injection.