Communitygithub.com

ComeOnOliver/skillshub

文件系统路由、布局和路由组。在Next.js中实现App Router路由、嵌套布局或路由组时使用。(触发条件:app/**/page.tsx、app/**/layout.tsx、app/**/loading.tsx、App Router、Layout、Route Group、parallel routes)

skillshub 是什么?

该技能为AI编码代理(如Claude Code、Cursor、Codex)提供了在Next.js中实现App Router文件系统路由、布局和路由组的全面指南。它涵盖了核心架构模式,包括使用`app/`目录定义路由、基于Route Groups(`(auth)`)的URL路径排除、动态路由(`[slug]`)及通过`generateStaticParams`生成静态路径,以及处理loading、error和not-found状态。技能重点强调了Next.js 15+的异步API变更——必须`await` `params`、`searchParams`、`cookies()`和`headers()`——并建议在边缘端使用`middleware.ts`进行身份验证。它还推荐默认使用React Server Components(RSC),仅在叶节点使用`'use client'`进行交互性操作,并通过`loading.tsx`和`error.tsx`提供内置的Suspense和错误边界支持。该技能支持Claude Code、Cursor和Codex等平台,其SKILL.md文件包含实现指南、文件约定、结构模式、最佳实践和反模式,确保路由实现稳健且安全。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/HoangNguyen0403/agent-skills-standard/nextjs-app-router

在你喜欢的 AI 中提问

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

文档

优先级:P0(关键)

实现指南

路由架构

  • 结构:使用 app/ 目录。通过 app/dashboard/layout.tsx 定义路由,返回 {children};共享UI自动嵌套在 app/layout.tsx 中。使用 loading.tsx、error.tsx 和 not-found.tsx 处理状态。
  • 段(Segments):使用 Route Groups(括号 (auth))组织功能,使其 从URL路径中排除。使用 动态路由(括号 [slug])并通过 generateStaticParams 定义静态路径。
  • 高级路由:使用 并行路由(Parallel Routes)(@modal),将插槽(slot)添加到父布局并提供 default.tsx 回退。使用 拦截路由(Intercepting Routes)((.)route)实现高级布局,如仪表板。

数据与函数

  • Next.js 15+ 异步:始终 await params: Promise、searchParams、cookies() 和 headers()。
  • 安全性:使用 middleware.ts 进行边缘端身份验证和重定向。确保所有 路由处理器(route.ts) 都经过适当的身份验证检查。
  • RSC:默认使用 React Server Components(RSC)。仅在叶节点使用 'use client' 进行交互性操作(钩子/事件)。
  • 错误边界:创建 app/dashboard/loading.tsx 以自动将路由包装在 Suspense边界 中。在 error.tsx 中,使用 'use client' 并提供一个 reset: () => void 函数。

代码片段

// app/dashboard/layout.tsx
export default async function DashboardLayout({
  children,
  analytics,
}: {
  children: React.ReactNode
  analytics: React.ReactNode
}) {
  const cookieStore = await cookies()
  const theme = cookieStore.get('theme')

  return (
    <div className={theme?.value ?? 'light'}>
      {children}
      {analytics}
    </div>
  )
}

文件约定

  • page.tsx:路由的UI。
  • layout.tsx:包裹子元素的共享UI。在导航间保持持久化。
  • loading.tsx:加载状态的Suspense边界。
  • error.tsx:错误边界(必须是客户端组件)。
  • route.ts:服务器端API端点。

结构模式

  • 路由组(Route Groups):使用括号 (auth) 组织,不影响URL路径。
  • 私有文件夹(Private Folders):使用下划线 _lib 排除在路由之外。
  • 动态路由(Dynamic Routes):使用方括号 [slug] 或 [...slug](全捕获)。

最佳实践

  • RSC边界:确保传递给客户端组件的props是可序列化的。参见 RSC边界与序列化。
  • 并行路由(@folder):在同一布局中渲染多个页面。使用 default.tsx 作为回退。
  • 拦截路由((..)folder):在当前布局上下文中加载路由。
  • 同地组织(Colocation):将组件文件、样式和测试存放在路由文件夹内。
  • 布局(Layouts):使用根布局(app/layout.tsx)放置 <html> 和 <body> 标签。
  • 自托管标准

反模式

  • 不要使用未等待的异步API:params、cookies()、headers() 在Next.js 15+中是Promise;始终await。
  • 不要在树根使用 'use client':将其放在叶子节点;保持布局和页面为服务器组件。
  • 不要在嵌套布局中使用 <html>/<body>:只有 app/layout.tsx(根布局)应包含它们。
  • 不要缺少 error.tsx:每个路由段都需要一个客户端组件错误边界。

Individual skills in this repo

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

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

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.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相关技能