From a745fee868f7ff4ed6c2efdf4512970c19c04e10 Mon Sep 17 00:00:00 2001 From: emmafallancy Date: Wed, 22 Nov 2017 00:32:02 +1100 Subject: [PATCH 1/2] Restore layout for page not found when navigating from other page --- packages/gatsby/cache-dir/component-renderer.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/cache-dir/component-renderer.js b/packages/gatsby/cache-dir/component-renderer.js index e9272dc449cc1..dea789bf78a9d 100644 --- a/packages/gatsby/cache-dir/component-renderer.js +++ b/packages/gatsby/cache-dir/component-renderer.js @@ -45,14 +45,26 @@ class ComponentRenderer extends React.Component { nextProps.location.pathname ) if (!pageResources) { + let location = nextProps.location + + // This edge case strictly cover for page not found. + // This attempt is to restore layout for page not found + // when back button is pushed after navigating to different page. + if (!loader.getPage(location.pathname)) { + location = Object.assign({}, location, { + ...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, }) } From 478896f9d19c1b522885b11335d4a27a101cd08b Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 27 Nov 2017 18:04:05 -0800 Subject: [PATCH 2/2] Update component-renderer.js --- packages/gatsby/cache-dir/component-renderer.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/gatsby/cache-dir/component-renderer.js b/packages/gatsby/cache-dir/component-renderer.js index dea789bf78a9d..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`, }) } @@ -47,12 +46,9 @@ class ComponentRenderer extends React.Component { if (!pageResources) { let location = nextProps.location - // This edge case strictly cover for page not found. - // This attempt is to restore layout for page not found - // when back button is pushed after navigating to different page. + // Set the pathname for 404 pages. if (!loader.getPage(location.pathname)) { location = Object.assign({}, location, { - ...location, pathname: `/404.html`, }) }