Personalized server-rendered pages
A dashboard must show data personalized to the signed-in user on every request.
Next.js 16+ · Type Alias
Deprecated Pages Router function for fetching data and rendering a page on every request. In the App Router, use server-side data fetching with fetch and async React Server Components instead.
This Pages Router function runs on the server for every request, fetches request-time data, and returns serializable props used to render the page. In the App Router, its role is replaced by server-side data fetching with fetch and async React Server Components.
export async function getServerSideProps(context: GetServerSidePropsContext): Promise<GetServerSidePropsResult<Props>>| Name | Type | Description |
|---|---|---|
context | GetServerSidePropsContext | Request context containing the documented request, response, route, query, locale, and preview-related values. |
An object with a documented return property such as props; props must be a serializable key-value object whose values are passed to the page component. The function may also return notFound or redirect.
export default function Page({ data }: { data: string }) {
return <p>{data}</p>
}
export async function getServerSideProps() {
const res = await fetch("https://example.com/data")
const data = await res.text()
return { props: { data } }
}A Pages Router page exports the function and receives its returned serializable props.
A dashboard must show data personalized to the signed-in user on every request.
A page needs authorization headers or geolocation that exist only in the current request.
Frequently changing data should be rendered on the server rather than generated at build time.
It is a Pages Router function that runs on the server at request time. Its returned props are used to render the page's initial HTML.
Follow-up: How does client navigation work? Next.js sends an API request to the server, which runs the function and returns its JSON result.
Use it when the page depends on personalized data or information available only for the current request, such as authorization headers or geolocation.
Follow-up: When would it be a poor choice? For data that can be generated at build time, request-time rendering adds unnecessary server work and latency.
The function can use server-only modules, including database access, because top-level imports used by it are not bundled for the client. It must return serializable props or another documented return shape.
Follow-up: What replaces it in the App Router? Use the App Router's server-side data-fetching APIs with fetch and async React Server Components.
getStaticPropsgetStaticPathsfetchServer ComponentsApp RouterPages Router