SuperAPI AI 工具集

nextjs-app-router-patterns

前端与建站

查看项目

更新于 10-16 00:30

技能介绍

用途:提供 Next.js 14+ App Router 架构、Server Components 与现代全栈 React 开发的系统化模式参考,用于新建 App Router 应用、从 Pages Router 迁移、实现服务端组件与流式渲染、配置并行与拦截路由、优化数据获取与缓存,以及用 Server Actions 构建全栈功能。

主要能力:区分 Server Components、Client Components、静态、动态与流式等渲染模式;说明 app/ 目录文件约定,如 layout.tsx、page.tsx、loading.tsx、error.tsx、not-found.tsx、route.ts、template.tsx、default.tsx、opengraph-image.tsx;给出服务端数据获取与 Suspense 流式、'use client' 客户端组件、Server Actions 变更与重验证、并行路由、拦截路由(模态)、路由处理器、Metadata 与 SEO 等模式。

必要用法:默认使用 Server Components,仅在需要交互、hooks 或浏览器 API 时加 'use client';在数据使用处就近获取并用 Suspense 包裹慢数据;用 revalidateTag、revalidatePath 做缓存失效;缓存策略包括 cache: "no-store"、cache: "force-cache"、next: { revalidate: 60 }、next: { tags: ["products"] }。

限制:资料未提供该技能的安装命令、价格或平台信息;不要向客户端组件传递不可序列化数据,Server Components 中不可用 useState、useEffect 等 hooks。