app directory define your routes. This guide walks through how to create pages, layouts, nested routes, dynamic segments, and links.
Creating a page
A page is UI rendered on a specific route. Create a page by adding apage file inside the app directory and default-exporting a React component.
Creating a layout
A layout is UI shared between multiple pages. On navigation, layouts preserve state, remain interactive, and do not re-render. Create a layout by default-exporting a React component from alayout file. The component must accept a children prop, which will receive a page or another nested layout.
app/layout.tsx is the root layout. It is required and must contain <html> and <body> tags.
Creating a nested route
A nested route is a route composed of multiple URL segments. For example,/blog/[slug] is composed of three segments:
/(Root Segment)blog(Segment)[slug](Leaf Segment)
- Folders define the route segments that map to URL segments.
- Files like
pageandlayoutdefine the UI shown for a segment.
/blog, create a blog folder inside app, then add a page.tsx file inside it:
Nesting layouts
Layouts in the folder hierarchy are nested by default — they wrap child layouts via theirchildren prop.
To create a layout for /blog, add a layout file inside the blog folder:
app/layout.js) wraps the blog layout (app/blog/layout.js), which in turn wraps the blog index page (app/blog/page.js) and every blog post page (app/blog/[slug]/page.js).
Creating a dynamic segment
Dynamic segments let you generate routes from data. Wrap a folder name in square brackets to create a dynamic segment:[segmentName].
For example, app/blog/[slug]/page.tsx creates a dynamic route for each blog post where [slug] is the dynamic parameter:
Rendering with search params
In a Server Component page, you can read search parameters from the URL using thesearchParams prop:
Using
searchParams opts your page into dynamic rendering because it requires an incoming request to read the search parameters. Client Components can read search params using the useSearchParams hook instead.When to use each approach
| Use case | Approach |
|---|---|
| Load data based on search params (pagination, DB filtering) | searchParams prop in Server Component |
| Filter a list already loaded via props (client-only) | useSearchParams hook in Client Component |
| Read params in event handlers without re-renders | new URLSearchParams(window.location.search) |
Linking between pages
Use the<Link> component to navigate between routes. <Link> is a built-in Next.js component that extends the HTML <a> tag to provide prefetching and client-side navigation.
<Link> is the primary way to navigate between routes. You can also use the useRouter hook for more advanced navigation patterns.
Route Props Helpers
Next.js exposes globally-available utility types that inferparams and named slots from your route structure — no imports required. They are generated when running next dev, next build, or next typegen.
PageProps— props forpagecomponents, includingparamsandsearchParams.LayoutProps— props forlayoutcomponents, includingchildrenand any named slots.
app/blog/[slug]/page.tsx
app/dashboard/layout.tsx
Static routes resolve
params to {}. Types are generated during next dev, next build, or next typegen.