Skip to content

Commit

Permalink
Fix back/forward not working after 404
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bailey committed Nov 13, 2018
1 parent 465a4d2 commit c62c378
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/gatsby/cache-dir/ensure-resources.js
Expand Up @@ -100,7 +100,15 @@ class EnsureResources extends React.Component {
!(this.state.pageResources && this.state.pageResources.json)
) {
console.error(`Failed to get resources for ${location.pathname}`)
window.location.reload()

// Do this, rather than simply `window.location.reload()`, so that
// pressing the back/forward buttons work - otherwise Reach Router will
// try to handle back/forward navigation, causing the URL to change but
// the page displayed to stay the same.
const originalUrl = new URL(location.href)
window.history.replaceState({}, `404`, `${location.pathname}?gatsby-404`)
window.location.replace(originalUrl)

return null
}

Expand Down

0 comments on commit c62c378

Please sign in to comment.