在 App Router 中,app/ 目录内的文件夹结构定义了你的路由 — 无需编写路由配置。每个文件夹是一个 URL 段,其中的特殊文件定义了该段呈现的内容。
文件夹 = URL 段
text
app/
page.tsx → /
about/page.tsx → /about
blog/page.tsx → /blog
blog/[slug]/page.tsx → /blog/:slug (dynamic segment)
shop/(sale)/page.tsx → /shop (route group — parentheses don't add to URL)
特殊文件
每个文件夹可以包含保留的文件名,每个都有特定的作用:
text
page.tsx → the route's UI (REQUIRED to make a segment routable)
layout.tsx → shared wrapper that persists across child routes
loading.tsx → loading UI (auto-wraps the page in <Suspense>)
error.tsx → error boundary for the segment
not-found.tsx→ 404 UI
route.ts → an API endpoint (instead of a page)
