Next.js Routing relies on a clean, file-based routing architecture inside the app/ folder. Folders define route segments, and special filenames create accessible web pages and layouts.
In Next.js, every folder inside app/ represents a URL path segment. Adding a page.tsx file inside a folder makes that route segment publicly reachable in the browser.
flowchart TD
app["app/"] --> page["page.tsx -> /"]
app --> about["about/"]
about --> aboutPage["page.tsx -> /about"]
app --> blog["blog/"]
blog --> slug["[slug]/"]
slug --> slugPage["page.tsx -> /blog/:slug"]
Here is how folder structures translate directly into web URLs:
| Folder Structure | Accessible URL |
|---|---|
app/page.tsx |
/ |
app/about/page.tsx |
/about |
app/dashboard/settings/page.tsx |
/dashboard/settings |
When building pages like blog posts or user profiles, route segments need dynamic values. Wrap a folder name in square brackets [slug] to create dynamic routes:
// app/blog/[slug]/page.tsx
interface PageProps {
params: Promise<{ slug: string }>;
}
export default async function BlogPostPage({ params }: PageProps) {
const { slug } = await params;
return (
<article className="p-6">
<h1 className="text-2xl font-bold">Reading Article: {slug}</h1>
<p className="mt-4">This content renders dynamically for slug parameter: {slug}</p>
</article>
);
}
(groupName)Organize routes without affecting URL path names by placing folder names in parentheses (marketing) or (shop):
app/
├── (marketing)/
│ ├── about/page.tsx -> /about
│ └── contact/page.tsx -> /contact
└── (checkout)/
└── cart/page.tsx -> /cart
page.tsx, layout.tsx, loading.tsx, error.tsx).Next.js routing replaces complex router code with intuitive folder nesting. Dynamic routes and route groups give you total control over application URL architecture.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With