Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
fix: scroll behaviour, now it's a 2 liner
Browse files Browse the repository at this point in the history
probably due to upgrade to gatsby@2.0.10
  • Loading branch information
CanRau committed Oct 6, 2018
1 parent de89abb commit 535235c
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 535235c

Please sign in to comment.