02 / 12
Pages, layouts, dynamic segments, route groups and navigating with Link.
The App Router is file-based. Every folder is a segment in the URL, and the page.tsx in that folder is the page at that address.1
app/
├── layout.tsx # wraps every page
├── page.tsx # /
└── products/
├── layout.tsx # wraps /products and everything below it
├── page.tsx # /products
└── [slug]/
└── page.tsx # /products/canvas-sneakerA layout wraps the pages below it as children. When the user moves from /products/a to /products/b, the shared layout is not re-rendered; its state and scroll position are kept and only the page changes.1
// app/products/layout.tsx
export default function ProductsLayout({ children }: LayoutProps<"/products">) {
return (
<section>
<aside>Categories</aside>
{children}
</section>
);
}LayoutProps and PageProps are global types you use without importing. Next.js generates them from your folders during next dev, next build or next typegen, so you never write the params type by hand.1
Because a layout is not re-rendered, it has two limits:2
It cannot take searchParams; the value would go stale. Read the URL parameter on the page, or with useSearchParams in a Client Component.
It cannot take pathname for an active menu item. Move the links into a small Client Component that uses usePathname.
Warning
Do not put the session check in a layout. Because a layout does not run again on navigation, it does not protect every page below it. Do the check close to the data; the Auth in Next.js lesson covers this in detail.
A folder in square brackets is for pages generated from data:3
| Folder | Matching address |
|---|---|
[slug] | /products/canvas-sneaker |
[...slug] | /shop/shoes, /shop/shoes/sneakers |
[[...slug]] | /docs, /docs/setup, /docs/setup/node |
// app/products/[slug]/page.tsx
export default async function ProductPage({ params }: PageProps<"/products/[slug]">) {
const { slug } = await params;
const product = await getProduct(slug);
return <h1>{product?.name}</h1>;
}params and searchParams are a promise; you cannot use them without an await. Older tutorials read params.slug directly; that changed in Next.js 15.4
Tip
To keep them short, the examples in this and the next few lessons read params at the top of the page. With Partial Prefetching on, Next.js flags that with a warning in development, because every link to a route shares a single shell. In a real project, read params in a child inside a <Suspense>. The reason is in the Navigation and prefetching lesson.5
| What you need | Use |
|---|---|
| Fetching data from the server with a filter and pagination | The page's searchParams prop |
| Filtering a list that is already loaded, on the client | The useSearchParams hook |
Reading searchParams ties that part of the page to request time. With Cache Components you have to do it inside a <Suspense>; you will see why in the Cache and the rendering model lesson.1
A folder in parentheses is not added to the URL but can have a layout of its own. To give the shop and the marketing pages different top menus:6
app/
├── (marketing)/
│ ├── layout.tsx # the marketing menu
│ └── about/page.tsx # /about
└── (shop)/
├── layout.tsx # the shop menu and the cart
└── cart/page.tsx # /cartDelete the root app/layout.tsx and give each group its own layout with an <html> in it, and you have set up more than one root layout. Moving between the groups reloads the page completely.6
<Link> extends <a>. It prefetches the destination of visible links in the background and moves to the page on a click without a reload; the shared layouts stay in place.7
import Link from "next/link";
<Link href={`/products/${product.slug}`}>{product.name}</Link>;For navigating from code there is useRouter. The right place to import it from is next/navigation. next/router belongs to the old Pages Router and does not work in the App Router.8 AI tools confuse the two often.
For forms that write a parameter into the URL, such as a search, there is next/form. It behaves like a <form> but turns the submit into a client-side navigation, and works before JavaScript has loaded:9
import Form from "next/form";
<Form action="/products">
<input name="q" aria-label="Search products" />
<button>Search</button>
</Form>;Tip
Turn on typedRoutes: true in next.config.ts and a typo such as <Link href="/prodcts"> becomes a type error.10
Two patterns are for particular interfaces and are not needed in every project:1112
| Pattern | Folder | Example |
|---|---|---|
| Parallel route | @cart/ | Two sections in one layout that load independently |
| Intercepting route | (.)photo/[id] | Showing a photo opened from a list as a modal, and full-page when the link is shared |
In app/products/[slug]/page.tsx, read params.slug directly without an await. What does TypeScript say?
Add a counter button (a Client Component) to products/layout.tsx. Navigate between two products; does the counter reset?
Write a NavLink that marks the active menu item with usePathname.
Turn on typedRoutes and link to an address that does not exist.
Official docs: the "Layouts and Pages" and "Linking and Navigating" pages; they set out how prefetching, streaming and client-side transitions work together.17
Official docs: the "Caveats" section of the layout.js reference; it shows with examples why a layout does not take searchParams or pathname.2
Official docs: the layout and navigation chapters of the Next.js Learn course.13
Sources
Pages, nested layouts, dynamic segments, `searchParams` and the `PageProps`/`LayoutProps` helpers.
A layout not being re-rendered, the `searchParams` and `pathname` limits, and an active link example.
`[slug]`, catch-all and optional catch-all segments.
`params`, `searchParams`, `cookies` and `headers` becoming async.
URL data not belonging in the shared App Shell, and moving `params` inside a `<Suspense>`.
Grouping without affecting the URL, a group-specific layout, and more than one root layout.
Prefetching, streaming, client-side transitions, and the causes of a slow transition.
Importing from `next/navigation`, `push`, `replace`, `refresh`, and the difference from the Pages Router.
Forms that write URL parameters, client-side navigation and progressive enhancement.
Type-safe links with `typedRoutes`.
`@slot` folders and `default.tsx`.
The `(.)` and `(..)` patterns, and a modal example.
The layout and pages chapter of the course.
Check the lesson's main ideas with three questions.
Your progress is stored only in this browser.
Last updated: November 3, 2026