Introduction
Nested routes help organize pages in a clear folder structure. They make your app easier to navigate and maintain.
Nested routes help organize pages in a clear folder structure. They make your app easier to navigate and maintain.
app/
folderName/
page.tsx
subFolder/
page.tsxEach folder inside app/ represents a route segment.
A page.tsx file inside a folder becomes the page for that route.
/about.app/
about/
page.tsx/blog and dynamic nested routes like /blog/post-1.app/
blog/
page.tsx
[slug]/
page.tsx/dashboard/settings.app/
dashboard/
settings/
page.tsxThis example shows a /dashboard page and a nested /dashboard/profile page. Each page is in its own folder with a page.tsx file.
app/
dashboard/
page.tsx
profile/
page.tsx
// app/dashboard/page.tsx
export default function DashboardPage() {
return <h1>Dashboard Home</h1>;
}
// app/dashboard/profile/page.tsx
export default function ProfilePage() {
return <h1>User Profile</h1>;
}Folder names become URL parts automatically.
Use page.tsx inside folders to define pages.
Dynamic routes use square brackets, like [id].
Nested folders in app/ create nested routes.
Each page.tsx file is a page for its folder path.
This keeps your app organized and URLs clear.
page.tsx file inside a nested folder under app/ do?app/ represents a route segment in the URL.page.tsx in nested folderspage.tsx inside a nested folder creates a page for that nested route path./dashboard/settings in Next.js App Router?page.tsx file must be inside the deepest folder representing the route.app/:
app/
blog/
[slug]/
page.tsx
page.tsx
What URL will render the page inside app/blog/[slug]/page.tsx?[slug] represent dynamic route segments.:slug in URL patterns, meaning any value matches.app/
products/
page.tsx
details/
page.tsx
But navigating to /products/details shows a 404 error. What is the likely cause?details/page.tsx must be inside products/details/ folder to match the route /products/details.details/page.tsx inside app/ root, not nested under products/.details/page.tsx file is misplaced; it should be inside products/details/page.tsx. -> Option A/profile/settings/privacy in Next.js App Router. You also want to share a layout between /profile/settings and /profile/settings/privacy. How should you organize your folders and files inside app/?/profile/settings and /profile/settings/privacy, place layout.tsx inside settings/ folder.page.tsx inside settings/ and inside settings/privacy/ for those pages.Pass the test and this pattern moves unknown