diff --git a/src/AutoTop.ts b/src/AutoTop.ts new file mode 100644 index 0000000..f3a29ea --- /dev/null +++ b/src/AutoTop.ts @@ -0,0 +1,12 @@ +import { useLayoutEffect } from "react"; +import { useLocation } from "react-router-dom"; + +const AutoScorllTop = ({ children }) => { + const location = useLocation(); + useLayoutEffect(() => { + document.documentElement.scrollTo(0, 0); + }, [location.pathname]); + return children; +}; + +export default AutoScorllTop; diff --git a/src/main.tsx b/src/main.tsx index 16f96ee..98bf043 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -7,6 +7,7 @@ import { Provider } from "react-redux"; import store from "./store"; import { ConfigProvider } from "antd"; import zhCN from "antd/locale/zh_CN"; +import AutoScorllTop from "./AutoTop"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( @@ -15,7 +16,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( theme={{ token: { colorPrimary: "#ff4d4f" } }} > - + + +