1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Reload the page only if the change is for the current page. (#2589)

Sometimes, we've to reload the page for some changes.
Even if so, we need to do it if that change is for the current page.
This commit is contained in:
Arunoda Susiripala 2017-07-18 13:00:25 +05:30 committed by GitHub
parent c97aca50e5
commit 8ee024fd2d

View file

@ -32,17 +32,22 @@ export default () => {
const { err, Component } = Router.components[route] || {}
if (err) {
// reload to recover from runtime errors
Router.reload(route)
}
if (Router.route !== route) {
// If this is a not a change for a currently viewing page.
// We don't need to worry about it.
return
}
if (!Component) {
// This only happens when we create a new page without a default export.
// If you removed a default export from a exising viewing page, this has no effect.
console.log(`Hard reloading due to no default component in page: ${route}`)
window.location.reload()
return
}
if (err) {
// reload to recover from runtime errors
Router.reload(route)
}
}
}