page.js
API reference for the page.js file.
The page file allows you to define UI that is unique to a route. You can create a page by default exporting a component from the file:
Good to know
- The
.js,.jsx, or.tsxfile extensions can be used forpage. - A
pageis 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 be set to a Client Component.
Reference
Props
params (optional)
A promise that resolves to an object containing the dynamic route parameters from the root segment down to that page.
| Example 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'] }> |
- Since the
paramsprop is a promise, you must useasync/awaitor React'susefunction to access the values.- In version 14 and earlier,
paramswas a synchronous prop. To help with backwards compatibility, you can still access it synchronously in Next.js 15, but this behavior will be deprecated in the future.
- In version 14 and earlier,
searchParams (optional)
A promise that resolves to an object containing the search parameters of the current URL. For example:
Client Component pages can also access searchParams using React’s use hook:
| Example 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'] }> |
- Since the
searchParamsprop is a promise. You must useasync/awaitor React'susefunction to access the values.- In version 14 and earlier,
searchParamswas a synchronous prop. To help with backwards compatibility, you can still access it synchronously in Next.js 15, but this behavior will be deprecated in the future.
- In version 14 and earlier,
searchParamsis a Dynamic API whose values cannot be known ahead of time. Using it will opt the page into dynamic rendering at request time.searchParamsis a plain JavaScript object, not aURLSearchParamsinstance.
Page Props Helper
You can type pages with PageProps to get strongly typed params and searchParams from the route literal. PageProps is a globally available helper.
Good to know
- Using a literal route (e.g.
'/blog/[slug]') enables autocomplete and strict keys forparams. - Static routes resolve
paramsto{}. - Types are generated during
next dev,next build, or withnext typegen. - After type generation, the
PagePropshelper is globally available. It doesn't need to be imported.
Examples
Displaying content based on params
Using dynamic route segments, you can display or fetch specific content for the page based on the params prop.
Handling filtering with searchParams
You can use the searchParams prop to handle filtering, pagination, or sorting based on the query string of the URL.
Reading searchParams and params in Client Components
To use searchParams and params in a Client Component (which cannot be async), you can use React's use function to read the promise:
Version History
| Version | Changes |
|---|---|
v15.0.0-RC | params and searchParams are now promises. A codemod is available. |
v13.0.0 | page introduced. |