ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β π nextjs/app/api-reference/file-conventions/page β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β
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:
export default function Page({
params,
searchParams,
}: {
params: Promise<{ slug: string }>
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
return <h1>My Page</h1>
}
export default function Page({ params, searchParams }) {
return <h1>My Page</h1>
}
.js, .jsx, or .tsx file extensions can be used for page.page is always the leaf of the route subtree.page file is required to make a route segment publicly accessible.params (optional)A promise that resolves to an object containing the dynamic route parameters from the root segment down to that page.
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
}
export default async function Page({ params }) {
const { slug } = await params
}
| 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'] }> |
params prop is a promise, you must use async/await or React's use function to access the values.
params was 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.searchParams (optional)A promise that resolves to an object containing the search parameters of the current URL. For example:
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
const filters = (await searchParams).filters
}
export default async function Page({ searchParams }) {
const filters = (await searchParams).filters
}
Client Component pages can also access searchParams using Reactβs use hook:
'use client'
import { use } from 'react'
export default function Page({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
const filters = use(searchParams).filters
}
'use client'
import { use } from 'react'
export default function Page({ searchParams }) {
const filters = use(searchParams).filters
}
| 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'] }> |
searchParams prop is a promise. You must use async/await or React's use function to access the values.
searchParams was 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.searchParams is a Dynamic API whose values cannot be known ahead of time. Using it will opt the page into dynamic rendering at request time.searchParams is a plain JavaScript object, not a URLSearchParams instance.You can type pages with PageProps to get strongly typed params and searchParams from the route literal. PageProps is a globally available helper.
export default async function Page(props: PageProps<'/blog/[slug]'>) {
const { slug } = await props.params
const query = await props.searchParams
return <h1>Blog Post: {slug}</h1>
}
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.
paramsUsing dynamic route segments, you can display or fetch specific content for the page based on the params prop.
export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params
return <h1>Blog Post: {slug}</h1>
}
export default async function Page({ params }) {
const { slug } = await params
return <h1>Blog Post: {slug}</h1>
}
searchParamsYou can use the searchParams prop to handle filtering, pagination, or sorting based on the query string of the URL.
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
const { page = '1', sort = 'asc', query = '' } = await searchParams
return (
<div>
<h1>Product Listing</h1>
<p>Search query: {query}</p>
<p>Current page: {page}</p>
<p>Sort order: {sort}</p>
</div>
)
}
export default async function Page({ searchParams }) {
const { page = '1', sort = 'asc', query = '' } = await searchParams
return (
<div>
<h1>Product Listing</h1>
<p>Search query: {query}</p>
<p>Current page: {page}</p>
<p>Sort order: {sort}</p>
</div>
)
}
searchParams and params in Client ComponentsTo use searchParams and params in a Client Component (which cannot be async), you can use React's use function to read the promise:
'use client'
import { use } from 'react'
export default function Page({
params,
searchParams,
}: {
params: Promise<{ slug: string }>
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
const { slug } = use(params)
const { query } = use(searchParams)
}
'use client'
import { use } from 'react'
export default function Page({ params, searchParams }) {
const { slug } = use(params)
const { query } = use(searchParams)
}
| Version | Changes |
| ------------ | ---------------------------------------------------------------------------------------------------------------- |
| v15.0.0-RC | params and searchParams are now promises. A codemod is available. |
| v13.0.0 | page introduced. |
β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ