page file defines UI that is unique to a route. Pages are Server Components by default and can be made async to fetch data.
app/blog/[slug]/page.js
Good to know
- Supported file extensions:
.js,.jsx,.tsx - A page is always the leaf of the route subtree
- A
pagefile is required to make a route segment publicly accessible - Pages are Server Components by default but can use the
'use client'directive - In the component hierarchy,
page.jsis the innermost file, wrapped byloading.js,error.js,template.js, andlayout.js
Props
A promise that resolves to the dynamic route parameters from the root segment down to the page.
Use
app/shop/[slug]/page.js
| Route | URL | params |
|---|---|---|
app/shop/[slug]/page.js | /shop/1 | Promise<{ slug: '1' }> |
app/shop/[category]/[item]/page.js | /shop/1/2 | Promise<{ category: '1', item: '2' }> |
app/shop/[...slug]/page.js | /shop/1/2 | Promise<{ slug: ['1', '2'] }> |
async/await or React’s use() to read the value.A promise that resolves to the current URL’s search parameters.
app/shop/page.js
| URL | searchParams |
|---|---|
/shop?a=1 | Promise<{ a: '1' }> |
/shop?a=1&b=2 | Promise<{ a: '1', b: '2' }> |
/shop?a=1&a=2 | Promise<{ a: ['1', '2'] }> |
searchParams is a request-time API. Using it opts the page into dynamic rendering. It returns a plain object, not a URLSearchParams instance.TypeScript helper
Use the globalPageProps helper for strongly typed params and searchParams:
app/blog/[slug]/page.tsx
Types are generated during
next dev, next build, or next typegen. PageProps is globally available and does not need to be imported.Examples
Displaying content based on params
app/blog/[slug]/page.js
Filtering with searchParams
app/shop/page.js
Reading params in Client Components
Use React’suse() function to unwrap the promise in a Client Component:
app/page.js
Generating static pages
ExportgenerateStaticParams to statically generate pages at build time:
app/blog/[slug]/page.js
Version history
| Version | Changes |
|---|---|
v15.0.0-RC | params and searchParams are now promises |
v13.0.0 | page introduced |
