--- name: nextjs-app-router user-invocable: false description: Use when next.js App Router with layouts, loading states, and streaming. Use when building modern Next.js 13+ applications. allowed-tools: - Bash - Read --- # Next.js App Router Master the Next.js App Router for building modern, performant web applications with server components and advanced routing. ## App Directory Structure The app directory uses file-system based routing with special files: ```typescript app/ layout.tsx # Root layout (required) page.tsx # Home page loading.tsx # Loading UI error.tsx # Error UI not-found.tsx # 404 UI template.tsx # Re-rendered layout about/ page.tsx # /about blog/ layout.tsx # Blog-specific layout page.tsx # /blog loading.tsx # Blog loading state [slug]/ page.tsx # /blog/[slug] dashboard/ (auth)/ # Route group (doesn't affect URL) layout.tsx # Layout for auth routes settings/ page.tsx # /dashboard/settings profile/ page.tsx # /dashboard/profile // app/layout.tsx - Root layout (required) export default function RootLayout({ children }: { children: React.ReactNode }) { return (
{children}