【问题标题】:Why does getInitialProps runs on redirect but not on page refresh? (NextJS)为什么 getInitialProps 在重定向时运行而不是在页面刷新时运行? (NextJS)
【发布时间】:2020-04-29 09:25:24
【问题描述】:

一个快速的 NextJS 问题 -> 为什么当页面被重定向到时 getInitialProps 正在运行(例如使用 Router.push \ Router.replace),但没有在页面刷新时运行?这背后的原因是什么?

谢谢!

  • 我使用的是有点旧的 NextJS 版本 -> 6.12.0

【问题讨论】:

    标签: reactjs react-router next.js


    【解决方案1】:

    对于初始页面加载,getInitialProps 将在服务器上执行 只要。 getInitialProps 只会在客户端执行 通过下一个/链接组件或通过导航到不同的路线 使用下一个/路由器。

    这意味着它将在 Initial Page Load -Refreshes Apply- 中调用,它在服务器端执行,而不是在客户端执行。作为from

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      • 2016-05-12
      • 1970-01-01
      • 1970-01-01
      • 2012-07-07
      相关资源
      最近更新 更多