自动滚到到顶部

This commit is contained in:
禺狨
2023-04-17 11:19:15 +08:00
parent 23d16b52dd
commit 36a24ae87f
2 changed files with 16 additions and 1 deletions

12
src/AutoTop.ts Normal file
View File

@@ -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;