简体   繁体   中英

Why does getInitialProps runs on redirect but not on page refresh? (NextJS)

a quick NextJS Question -> Why does getInitialProps is running when a page is being redirected to (using Router.push \\ Router.replace for example), but isn't running on a page refresh? What's the rational behind this?

Thanks!

  • I'm using a bit old NextJS version -> 6.12.0

For the initial page load, getInitialProps will execute on the server only. getInitialProps will only be executed on the client when navigating to a different route via the next/link component or by using next/router.

This means it'll be invoked in Initial Page Load -Refreshes Apply- where it get's executed in the server side, not the client side. As from

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM