reactjs - How to fix Gatsby JS Link component retaining scroll position and not resetting to top - Stack Overflow

PHOTO EMBED

Thu Dec 17 2020 17:13:12 GMT+0000 (Coordinated Universal Time)

Saved by @richard #javascript

// in gastby-browser.js
exports.shouldUpdateScroll = ({
  routerProps: { location },
  getSavedScrollPosition,
}) => {
  const { pathname } = location
  // list of routes for the scroll-to-top-hook
  const scrollToTopRoutes = [`/privacy-policy`, `/page-2`]
  // if the new route is part of the list above, scroll to top (0, 0)
  if (scrollToTopRoutes.indexOf(pathname) !== -1) {
    window.scrollTo(0, 0)
  }

  return false
}
content_copyCOPY

https://stackoverflow.com/questions/55336831/how-to-fix-gatsby-js-link-component-retaining-scroll-position-and-not-resetting