1.Top-level folders 顶级文件夹
Top-level folders are used to organize your application's code and static assets.
顶级文件夹用于组织应用程序的代码和静态资产。
app | App Router |
pages | Pages Router |
public | Static assets to be served |
src | Optional application source folder |
2.Top-level files 顶级文件
Top-level files are used to configure your application, manage dependencies, run middleware, integrate monitoring tools, and define environment variables.
顶级文件用于配置应用程序、管理依赖项、运行中间件、集成监视工具以及定义环境变量。
| Configuration file for Next.js |
| Project dependencies and scripts |
| OpenTelemetry and Instrumentation file |
| Next.js request middleware |
| Environment variables 环境变量 |
| Local environment variables |
| Production environment variables |
| Development environment variables |
| Configuration file for ESLint |
| Git files and folders to ignore |
| TypeScript declaration file for Next.js |
| Configuration file for TypeScript |
| Configuration file for JavaScript |
3.app Routing Conventions app 路由约定
The following file conventions are used to define routes and handle metadata in the app router.
以下文件约定用于定义路由并处理 app 路由器中的元数据。
a. Routing Files 路由文件
|
| Layout 布局 |
|
| Page 页 |
|
| Loading UI 加载用户界面 |
|
| Not found UI 未找到用户界面 |
|
| Error UI 错误用户界面 |
|
| Global error UI 全局错误用户界面 |
|
| API endpoint API端点 |
|
| Re-rendered layout 重新渲染布局 |
|
| Parallel route fallback page |
b.Dynamic Routes 嵌套路由
| Route segment 航线段 |
| Nested route segment 嵌套路由段 |
c.Route Groups and Private Folders 路由组和私人文件夹
| Group routes without affecting routing |
| Opt folder and all child segments out of routing |
d.Parallel and Intercepted Routes 并行和拦截的路线
| Named slot 命名槽 |
| Intercept same level 拦截同级 |
| Intercept one level above |
| Intercept two levels above |
| Intercept from root 从根拦截 |
e.Metadata File Conventions 元数据文件约定
App Icons
Open Graph and Twitter Images
SEO
4.pages Routing Conventions pages 路由约定
The following file conventions are used to define routes in the pages router.
以下文件约定用于定义 pages 路由器中的路由。
a.Special Files 特殊文件
|
| Custom App 定制应用程序 |
|
| Custom Document 定制文件 |
|
| Custom Error Page 自定义错误页面 |
|
| 404 Error Page 404错误页面 |
|
| 500 Error Page 500 错误页面 |
b.Routes 路线
Folder convention 文件夹约定 | ||
|
| Home page 主页 |
|
| Nested page 嵌套页面 |
File convention 文件约定 | ||
|
| Home page 主页 |
|
| Nested page 嵌套页面 |
c.Dynamic Routes 动态路线
Folder convention 文件夹约定 | ||
|
| Dynamic route segment 动态路段 |
|
| Catch-all route segment 包罗万象的路线段 |
|
| Optional catch-all route segment |
File convention 文件约定 | ||
|
| Dynamic route segment 动态路段 |
|
| Catch-all route segment 包罗万象的路线段 |
|
| Optional catch-all route segment |