网页
综合
更新时间 2026-03-03 00:00:00
getServerSideProps
自动蜘蛛
nextjs.org
正文约 1334 字
getServerSideProps is a Next.js function that can be used to fetch data and render the contents of a page at request time.
You can use getServerSideProps by exporting it from a Page Component. The example below shows how you can fetch data from a 3rd party API in getServerSideProps, and pass the data to the page as props:
You should use getServerSideProps if you need to render a page that relies on personalized user data, or information that can only be known at request time. For example, authorization headers or a geolocation.
If you do not need to fetch the data at request time, or would prefer to cache the data and prerendered HTML, we recommend using getStaticProps.
If an error is thrown inside getServerSideProps, it will show the pages/500.js file. Check out the documentation for 500 page to learn more on how to create it. During development, this file will not be used and the development error overlay will be shown instead.
You can use caching headers (Cache-Control) inside getServerSideProps to cache dynamic responses. For example, using stale-while-revalidate.
However, before reaching for cache-control, we recommend seeing if getStaticProps with ISR is a better fit for your use case.
Last updated March 3, 2026
Subscribe to our newsletter
Stay updated on new releases and features, guides, and case studies.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。