score:0

i had this same issue with react-router v6 and using the following instead of window.scrollto(0, 0) worked for me:

useeffect(() => {
    document.body.scrollto(0, 0); 
});

score:2

try grabbing document.documentelement or another specific element instead of window.

const location = uselocation();
uselayouteffect(() => {
  document.documentelement.scrollto(0, 0);
}, [location.pathname]);

related: react-router scroll to top on every transition


Related Query

More Query from same tag