What is the page.js file in the App Router?
page.js (or .tsx) defines the unique UI of a route and is what makes a folder publicly accessible. app/blog/page.tsx serves /blog. Without a page (or route) file, a folder is not a route.
Props
params: a Promise of dynamic route params, for example{ slug: string }.searchParams: a Promise of the query string values (string | string[] | undefined).
Both must be awaited since Next.js 15; synchronous access was removed in 16. Use the generated PageProps<'/blog/[slug]'> type.
Behavior
- A Server Component by default. It can be
async, fetch data and callnotFound()orredirect(). - It renders inside every parent layout and is wrapped by the nearest
loading,errorandnot-foundboundaries. - Pages are leaf nodes: they cannot wrap other routes.
- Can export
metadataorgenerateMetadata,generateStaticParams, and route segment config such asensureStatic,instantandprefetch(with Cache Components).
Rendering
With Cache Components, the page is prerendered as far as possible. Parts that read searchParams, cookies or uncached data must sit inside <Suspense> or be cached with "use cache". Accessing searchParams at the top of the page makes the whole page request-time, so read it in a child component instead.
Client pages
You can add "use client" to a page, but you lose server data fetching and metadata exports for that page. In a Client Component page, read params with useParams() or React's use(props.params).
Code example
1// app/blog/[slug]/page.tsx2import type { Metadata } from "next";3import { notFound } from "next/navigation";4import { getPost } from "@/lib/posts"; // uses "use cache" internally56export async function generateMetadata({ params }: PageProps<"/blog/[slug]">): Promise<Metadata> {7 const { slug } = await params;8 const post = await getPost(slug);9 return { title: post?.title ?? "Not found" };10}1112export default async function BlogPost({ params }: PageProps<"/blog/[slug]">) {13 const { slug } = await params;14 const post = await getPost(slug);15 if (!post) notFound();1617 return (18 <article>19 <h1>{post.title}</h1>20 <div dangerouslySetInnerHTML={{ __html: post.html }} />21 </article>22 );23}
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.