Skip to main content
Next.js uses file-system based routing — folders and files inside the 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 a page 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 a layout file. The component must accept a children prop, which will receive a page or another nested layout.
The layout at 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)
In Next.js:
  • Folders define the route segments that map to URL segments.
  • Files like page and layout define the UI shown for a segment.
To add a route for /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 their children prop. To create a layout for /blog, add a layout file inside the blog folder:
With both layouts in place, the root layout (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:
To pre-generate static pages for a dynamic segment at build time, export generateStaticParams from the page. This avoids falling back to dynamic rendering at request time.

Rendering with search params

In a Server Component page, you can read search parameters from the URL using the searchParams 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

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 infer params and named slots from your route structure — no imports required. They are generated when running next dev, next build, or next typegen.
  • PageProps — props for page components, including params and searchParams.
  • LayoutProps — props for layout components, including children and 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.