ScrollToTop.jsx 483 B

1234567891011121314151617181920
  1. // hooks
  2. import {useEffect} from 'react';
  3. import {useLocation} from 'react-router-dom';
  4. const ScrollToTop = ({children}) => {
  5. const {pathname} = useLocation();
  6. useEffect(() => {
  7. const canControlScrollRestoration = 'scrollRestoration' in window.history
  8. if (canControlScrollRestoration) {
  9. window.history.scrollRestoration = 'manual';
  10. }
  11. window.scrollTo(0, 0);
  12. }, [pathname]);
  13. return children;
  14. }
  15. export default ScrollToTop