AgentSkillsCN

nextjs-app-router

利用官方的Next.js文档,构建、调试或迁移Next.js App Router的功能。在app/目录中工作时,可实现布局/页面、路由/导航、路由处理器、数据获取、缓存/重新验证、元数据,或在next.config.js中配置App Router。

SKILL.md
--- frontmatter
name: nextjs-app-router
description: Build, debug, or migrate Next.js App Router features using the official Next.js documentation. Use when working in the app/ directory, implementing layouts/pages, routing/navigation, route handlers, data fetching, caching/revalidation, metadata, or App Router configuration in next.config.js.

Next.js App Router

Use the App Router with the official docs as the source of truth. Keep work aligned to the project’s Next.js version and existing routing style. References contain condensed notes and examples derived from the official App Router docs.

Workflow

  1. Confirm App Router usage: look for app/, layout.*, page.*, or route.*.
  2. Read the Next.js version from package.json.
  3. Pick the task category below and open the matching reference.
  4. Implement changes using file-system conventions.
  5. Validate with the project’s dev/test commands if available.

Core

TopicDescriptionReference
Project StructureUnderstand app/, route segments, and conventionscore-project-structure
Layouts & PagesApply layout, page, template, loading, error, not-foundcore-layouts-pages
Routing & NavigationUse file-system routing, dynamic segments, and navigationcore-routing-navigation
Server & Client ComponentsDecide boundaries and apply "use client" only when neededcore-server-client-components
Data FetchingUse async Server Components and built-in fetch patternscore-data-fetching
Caching & RevalidationUse caching defaults and revalidation controlscore-caching-revalidation
Error HandlingUse error and not-found patterns consistentlycore-error-handling
Metadata & OGSet static/dynamic metadata and OG imagescore-metadata
Route HandlersImplement route.* handlers and HTTP methodscore-route-handlers
ConfigurationUpdate next.config.js for App Router behaviorcore-config

Rules of Thumb

  • Prefer Server Components by default; add "use client" only when required.
  • Avoid Pages Router APIs (getServerSideProps, getStaticProps, next/router) unless explicitly requested.
  • Follow file-system conventions instead of custom routing.