文件系统路由基础
了解 Next.js 中文件系统路由的基本概念,以及如何创建基本页面和路由
文件系统路由基础 是 CoddyKit 上的免费 Next.js 15 Fullstack (App Router + Server Actions) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Next.js 15 Fullstack (App Router + Server Actions) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Next.js 15 Fullstack (App Router + Server Actions) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Intro to File-System Routing
Next.js routes by your file system — your folder and file layout directly defines your URLs. Files become pages, folders become URL segments.
The Core `app` Directory
Every route lives inside the special app directory — the root of your site's structure. Anything you put there shapes the routing.
Creating a Root Page
A route needs a page.js that default-exports a React component. Place it directly in app/ and it becomes your homepage at /.
Hello Next.js Homepage!
Here's a minimal app/page.js. This component renders at your root URL / — the homepage visitors land on first.
export default function HomePage() {
return (
<div>
<h1>Welcome to CoddyKit!</h1>
<p>This is your Next.js homepage.</p>
</div>
);
}Folders for Nested Paths
Want a /dashboard route? Make a dashboard folder in app/ and drop a page.js inside. The folder name becomes the URL segment.
The Dashboard Page
This code goes in app/dashboard/page.js. Visit /dashboard and Next.js renders exactly this component.
export default function DashboardPage() {
return (
<div>
<h1>Your Dashboard</h1>
<p>Here you'll find all your important stats.</p>
</div>
);
}Deeper Nested Routes
Nest as deep as you like — each folder adds a URL segment. So app/products/electronics/page.js maps to /products/electronics. Clean and logical.
Shared UI with `layout.js`
A layout.js defines shared UI that wraps the pages in its folder — perfect for nav bars, footers, and sidebars that stay put across routes.
Route Mapping Quiz
Imagine you have a file located at app/blog/posts/page.js within your Next.js project. What URL path would this file correspond to?
File-System Routing Recap
Recap: the app directory roots all routes, page.js defines a route's UI, folders create nested segments, and layout.js shares UI across them.
常见问题解答
「文件系统路由基础」课时是免费的吗?
是的 — 「文件系统路由基础」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Next.js 15 Fullstack (App Router + Server Actions) 课程的其余内容,请升级到 CoddyKit PRO。 Next.js 15 Fullstack (App Router + Server Actions) 课程共包含 4 节课。
「文件系统路由基础」这节课中我会学到什么?
了解 Next.js 中文件系统路由的基本概念,以及如何创建基本页面和路由 你通过在浏览器中直接运行的动手代码来练习 Next.js 15 Fullstack (App Router + Server Actions),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Next.js 15 Fullstack (App Router + Server Actions) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Next.js 15 Fullstack (App Router + Server Actions) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「文件系统路由基础」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Next.js 15 Fullstack (App Router + Server Actions) 课中编写并运行代码吗?
能。每节 Next.js 15 Fullstack (App Router + Server Actions) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。