📜  单击反应后将站点置于顶部 - Javascript 代码示例

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

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

    const ScrollToTop = ({ children, location: { pathname } }) => {
      useEffect(() => {
        window.scrollTo({
          top: 0,
          left: 0,
          behavior: "smooth"
        });
      }, [pathname]);

      return children || null;
    };

    export default withRouter(ScrollToTop);