未验证 提交 f4bf8a46 编写于 作者: C Curt Siffert 提交者: GitHub

Update getInitialProps.md (#19506)

To clarify what I've noticed as a common source of confusion in discussions online. Fixes https://github.com/vercel/next.js/issues/19426 

If you wish to know whether the code is running as part of a client-side page transition, in either `getInitialProps` or `getServerSideProps`, you can check to see if `context.req.url` starts with `/_next/data`.
上级 86a0c7b0
......@@ -54,7 +54,7 @@ export default Page
Data returned from `getInitialProps` is serialized when server rendering, similar to what [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) does. Make sure the returned object from `getInitialProps` is a plain `Object` and not using `Date`, `Map` or `Set`.
For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then run on the client when navigating to a different route via the [`next/link`](/docs/api-reference/next/link.md) component or by using [`next/router`](/docs/api-reference/next/router.md).
For the initial page load, `getInitialProps` will run on the server only. `getInitialProps` will then run on the client when navigating to a different route via the [`next/link`](/docs/api-reference/next/link.md) component or by using [`next/router`](/docs/api-reference/next/router.md). However, if `getInitialProps` is used in a custom `_app.js`, and the page being navigated to implements `getServerSideProps`, then `getInitialProps` will run on the server.
## Context Object
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册