We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
如题
The text was updated successfully, but these errors were encountered:
https://blog.logrocket.com/getinitialprops-vs-getserversideprops-nextjs/
能够在 build 阶段就执行预渲染,会被打包到静态文件当中,可以进行 CDN
可以发起请求,更多的使用在 CMS 之类的无权限的静态资源请求上面
getInitialProps 会在首次加载的情况下,在服务端执行,后续通过 next/link、next/router 进入的页面将会在客户端执行
next/link
next/router
getInitialProps 是页面组件的静态方法,通过使用
Index.getInitialProps = async (ctx) => { ... }
来挂载方法
getInitialProps 中不应该出现服务端方法,因为可能在客户端执行,会报错
getServerSideProps 当中可以执行服务端方法,无论是在服务端渲染还是客户端渲染,完全可以替代 getInitialProps 方法
在页面的的文件下,导出
export async function getServerSideProps(context) { return { props: {}, // will be passed to the page component as props } }
如果是开发新版本的 Nextjs 应用,推荐使用新方法 getStaticProps 和 getServerSideProps, 放弃使用 getInitialProps 方法
Sorry, something went wrong.
No branches or pull requests
如题
The text was updated successfully, but these errors were encountered: