📜  处理反应路由器转换上的滚动 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:03:12.388000             🧑  作者: Mango

代码示例1
import { useEffect } from 'react';
import { withRouter } from 'react-router-dom';

function ScrollToTop({ history }) {
  useEffect(() => {
    const unlisten = history.listen(() => {
      window.scrollTo(0, 0);
    });
    return () => {
      unlisten();
    }
  }, []);

  return (null);
}

export default withRouter(ScrollToTop);