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:
parent
c97aca50e5
commit
8ee024fd2d
|
@ -32,17 +32,22 @@ export default () => {
|
||||||
|
|
||||||
const { err, Component } = Router.components[route] || {}
|
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) {
|
if (!Component) {
|
||||||
// This only happens when we create a new page without a default export.
|
// 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.
|
// 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}`)
|
console.log(`Hard reloading due to no default component in page: ${route}`)
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (err) {
|
|
||||||
// reload to recover from runtime errors
|
|
||||||
Router.reload(route)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue