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
Promise<object>
A promise that resolves to the dynamic route parameters from the root segment down to the page.
app/shop/[slug]/page.js
Use
async/await or React’s use() to read the value.Promise<object>
A promise that resolves to the current URL’s search parameters.
app/shop/page.js
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
