From 535235c81e038f950c331310de5a21c4d196f5e8 Mon Sep 17 00:00:00 2001 From: CanRau Date: Thu, 27 Sep 2018 20:22:02 -0500 Subject: [PATCH] fix: scroll behaviour, now it's a 2 liner probably due to upgrade to gatsby@2.0.10 --- gatsby-browser.js | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/gatsby-browser.js b/gatsby-browser.js index 813847c..49a30c0 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -1,27 +1,2 @@ -/* global window, document */ -const idToJumpTo = `main-nav` - -const scrollToMenu = () => { - const el = document.getElementById(idToJumpTo) - if (el) return window.scrollTo(0, el.offsetTop - 20) - return false -} - -/** - * fix custom scroll behaviour using __navigatingToLink declared in Link.js - * by https://github.com/gatsbyjs/gatsby/issues/7454#issuecomment-415786239 - * as reach/router does not (yet) provide the used action for onRouteUpdate - */ -export const shouldUpdateScroll = () => { - if (window.__navigatingToLink === true) { - return [0, 0] - } - return true -} - -export const onRouteUpdate = () => { - if (window.__navigatingToLink === true) { - window.setTimeout(scrollToMenu, 10) - } - window.__navigatingToLink = false -} +export const shouldUpdateScroll = ({ prevRouterProps }) => + prevRouterProps && prevRouterProps.location ? `main-nav` : true