Next.js file-based routing means the folder structure inside your app directory is the routing table. There is no separate config file listing your routes. You create a folder, and Next.js turns it into a URL segment automatically.
Create a folder named blog inside the app directory, add a page.tsx file to it, and the App Router serves that page at /blog.
// app/blog/page.tsx
export default function BlogIndexPage() {
return <h1>Blog</h1>;
}Start the dev server and visit /blog in the browser. The heading renders. No route needed to be registered anywhere else, because the folder path and the file name did the registration for you.
Nesting folders nests the URL
Each additional folder level adds one more segment to the URL. A folder placed inside the blog folder becomes a path segment that follows /blog.
app/
blog/
page.tsx -> /blog
archive/
page.tsx -> /blog/archiveThe inner folder needs its own page file to be reachable on its own. Nesting folders without adding that file only nests the folder structure on disk, not the routes a visitor can open.
A route is not public until it has a page file
Creating a folder alone does not expose a URL. Next.js only makes a segment publicly accessible once that folder contains a page file, or a route file for an API endpoint. Everything else inside the app directory stays private by default.
// app/dashboard/settings/page.tsx
export default function SettingsPage() {
return <h1>Settings</h1>;
}Only /dashboard/settings becomes reachable here. If the parent dashboard folder has no page file of its own, visiting /dashboard returns a 404, even though the folder exists on disk.
This is what lets you colocate components, hooks, and utility files inside route folders. A helper file saved next to this page never becomes a URL, because its name does not match a routing convention.
Layouts wrap segments without adding a URL
A layout file renders shared UI around every page inside its folder, but it never adds its own segment to the path. Every page inside the same folder renders wrapped inside it, while the URL stays exactly what each page file defines.
// app/dashboard/layout.tsx
export default function DashboardLayout({
children,
}: {
children: React.ReactNode;
}) {
return <section className="dashboard-shell">{children}</section>;
}For the full rules on nesting and sharing layouts across pages, see layouts in Next.js.
What each special file does
| File role | Effect on routing |
|---|---|
| Page | Makes a segment public and renders its unique UI |
| Layout | Wraps child segments, adds no URL segment |
| Route handler | Makes a segment a JSON or API endpoint instead of a page |
Dynamic segments extend this same system with square-bracket folder names, which is covered in dynamic routes in Next.js.
Common mistake
Adding a folder and expecting it to route by itself is the most common mistake beginners make. Without a page file inside it, the folder stays invisible to visitors even though it appears in the project's file tree. If a route returns a 404 you did not expect, check for a missing page file before checking anything else in your configuration.
Rune AI
Key Insights
- Next.js file-based routing maps folders inside app directly to URL segments.
- Nesting folders nests the URL path, one level at a time.
- A route only becomes public when it has a page file or a route file.
- A layout file wraps the segments inside its folder without changing the URL.
- Files without a routing convention name can be colocated safely.
Frequently Asked Questions
Do I need a router package in the App Router?
Does every folder in app become a URL?
Can I put non-route files inside app?
Conclusion
File-based routing means the app directory's folder structure is the routing table. Nesting folders nests URL segments, and a page file is what turns a segment into a page a visitor can reach.
More in this topic
`generateMetadata` Explained with Real Examples
What generateMetadata does, when it runs, and how to use it for real routes: awaited params, deduplicated data fetching, extending parent metadata, and returning a 404 from metadata.
Canonical URLs in Next.js: `metadataBase`, `alternates.canonical`, and Dynamic Pages
How canonical URLs work in the Next.js App Router: setting metadataBase once, writing alternates.canonical per route, handling dynamic segments, and what happens when the base URL is missing.
Open Graph and Twitter Card Metadata in Next.js
How to write Open Graph and Twitter card metadata in the Next.js App Router: the openGraph and twitter fields, automatic card defaults, article tags, and image merge rules.