0

im read documentation gatsby with scroll-restoration but this not working in my case, so im find this issue yeah, if im spam refresh page back to top slowly upwards so im find something diferent not use hook useScrollRestoration on gatsby but use plugin shouldUpdateScroll in browser-gatsby.js and im find something code in stackoverflow is workingjust browser firefox ,but not chromium family like chrome , opera, and edge.

so , how this code worked in another browser ?

1 Answers1

0

okay im already this stuck , i hope this answer help everyone with same case. im add something with this code https://stackoverflow.com/a/58181253/16945930

and this fix my problem

// in gastby-browser.js
exports.shouldUpdateScroll = ({
    routerProps: { location },
    getSavedScrollPosition,
  }) => {
    const { pathname } = location
    // list of routes for the scroll-to-top-hook
    const currentPosition = getSavedScrollPosition(location)
    const scrollToTopRoutes = [`/id/`, `/en/`]
    // if the new route is part of the list above, scroll to top (0, 0)
    if (scrollToTopRoutes.indexOf(pathname) !== -1) {
      window.scrollTo(currentPosition * 0, 0)
      console.log(scrollToTopRoutes.indexOf(pathname))
    }
  
    return false
  }

at documentation shouldUpdateScroll

we can take number with function getSavedScrollPosition and add operator * with value 0 so everthing get dta location scroll page become 0

this worked in browser firefox and chromium family(chrome, opera, edge ). but dont know with safary browser