diff --git a/packages/gatsby/cache-dir/component-renderer.js b/packages/gatsby/cache-dir/component-renderer.js index e9272dc449cc1..c84ea01d74d35 100644 --- a/packages/gatsby/cache-dir/component-renderer.js +++ b/packages/gatsby/cache-dir/component-renderer.js @@ -14,10 +14,9 @@ class ComponentRenderer extends React.Component { super() let location = props.location - // This covers layout for when page not found, especially during production + // Set the pathname for 404 pages. if (!loader.getPage(location.pathname)) { location = Object.assign({}, location, { - ...location, pathname: `/404.html`, }) } @@ -45,14 +44,23 @@ class ComponentRenderer extends React.Component { nextProps.location.pathname ) if (!pageResources) { + let location = nextProps.location + + // Set the pathname for 404 pages. + if (!loader.getPage(location.pathname)) { + location = Object.assign({}, location, { + pathname: `/404.html`, + }) + } + // Page resources won't be set in cases where the browser back button // or forward button is pushed as we can't wait as normal for resources // to load before changing the page. loader.getResourcesForPathname( - nextProps.location.pathname, + location.pathname, pageResources => { this.setState({ - location: nextProps.location, + location, pageResources, }) }