mirror of
https://github.com/PlayEdu/backend
synced 2025-06-28 20:52:49 +08:00
自动滚到到顶部
This commit is contained in:
parent
23d16b52dd
commit
36a24ae87f
12
src/AutoTop.ts
Normal file
12
src/AutoTop.ts
Normal 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;
|
@ -7,6 +7,7 @@ import { Provider } from "react-redux";
|
|||||||
import store from "./store";
|
import store from "./store";
|
||||||
import { ConfigProvider } from "antd";
|
import { ConfigProvider } from "antd";
|
||||||
import zhCN from "antd/locale/zh_CN";
|
import zhCN from "antd/locale/zh_CN";
|
||||||
|
import AutoScorllTop from "./AutoTop";
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
@ -15,7 +16,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
|
|||||||
theme={{ token: { colorPrimary: "#ff4d4f" } }}
|
theme={{ token: { colorPrimary: "#ff4d4f" } }}
|
||||||
>
|
>
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<App />
|
<AutoScorllTop>
|
||||||
|
<App />
|
||||||
|
</AutoScorllTop>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
</Provider>
|
</Provider>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user