diff --git a/packages/gatsby-react-router-scroll/src/ScrollBehaviorContext.js b/packages/gatsby-react-router-scroll/src/ScrollBehaviorContext.js index ac9e996ca6f9c..1b9d30700c382 100644 --- a/packages/gatsby-react-router-scroll/src/ScrollBehaviorContext.js +++ b/packages/gatsby-react-router-scroll/src/ScrollBehaviorContext.js @@ -49,9 +49,14 @@ class ScrollContext extends React.Component { // The "scroll-behavior" package expects the "action" to be on the location // object so let's copy it over. - if (!location.action) { - location.action = `push` + + // Temp hack while awaiting https://github.com/reach/router/issues/119 + if (window.__navigatingToLink) { + location.action = `PUSH` + } else { + location.action = `POP` } + this.scrollBehavior.updateScroll(prevRouterProps, { history, location }) } diff --git a/packages/gatsby/cache-dir/navigation.js b/packages/gatsby/cache-dir/navigation.js index 9a64e1eeb5729..f7112bc849b0c 100644 --- a/packages/gatsby/cache-dir/navigation.js +++ b/packages/gatsby/cache-dir/navigation.js @@ -42,10 +42,17 @@ const onPreRouteUpdate = location => { const onRouteUpdate = location => { if (!maybeRedirect(location.pathname)) { apiRunner(`onRouteUpdate`, { location }) + // Temp hack while awaiting https://github.com/reach/router/issues/119 + window.__navigatingToLink = false } } -const navigate = (to, options) => { +const navigate = (to, options = {}) => { + // Temp hack while awaiting https://github.com/reach/router/issues/119 + if (!options.replace) { + window.__navigatingToLink = true + } + let { pathname } = parsePath(to) const redirect = redirectMap[pathname] @@ -109,6 +116,9 @@ function shouldUpdateScroll(prevRouterProps, { location: { pathname } }) { } function init() { + // Temp hack while awaiting https://github.com/reach/router/issues/119 + window.__navigatingToLink = false + setApiRunnerForLoader(apiRunner) window.___loader = loader window.___push = to => navigate(to, { replace: false })