# Next.js 15 App Router 完整指南 > 涵盖 App Router 核心约定、数据获取、Server Actions、路由系统、缓存策略、ISR 和中间件。 --- ## 一、App Router 核心约定 ### 1.1 文件约定 App Router 使用文件系统路由,每个文件夹代表一个路由段,特殊文件名有约定含义: ``` app/ ├── layout.tsx # 根布局(必须) ├── page.tsx # 首页 / ├── loading.tsx # 加载 UI(自动包裹 Suspense) ├── error.tsx # 错误 UI(自动包裹 ErrorBoundary) ├── not-found.tsx # 404 UI ├── global-error.tsx # 全局错误处理 ├── dashboard/ │ ├── layout.tsx # 仪表盘布局(嵌套布局) │ ├── page.tsx # /dashboard │ ├── loading.tsx # 仪表盘加载态 │ └── settings/ │ └── page.tsx # /dashboard/settings ``` ### 1.2 Layout(布局) Layout 在路由切换时保持状态,不重新渲染,适合放导航、侧边栏等共享 UI。 ```tsx // app/layout.tsx — 根布局 import { Inter } from 'next/font/google'; import '@/styles/globals.css'; const inter = Inter({ subsets: ['latin'] }); export const metadata = { title: { default: '我的应用', template: '%s | 我的应用' }, description: '应用描述', }; export default function RootLayout({ children }: { children: React.ReactNode }) { return (
{children}