mirror of
https://github.com/PlayEdu/frontend.git
synced 2025-06-08 15:50:08 +08:00
自动滚到到顶部
This commit is contained in:
parent
ec32b7a6d1
commit
df2ab806c6
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;
|
@ -8,6 +8,7 @@ import { ConfigProvider } from "antd";
|
|||||||
import zhCN from "antd/locale/zh_CN";
|
import zhCN from "antd/locale/zh_CN";
|
||||||
import App from "./App";
|
import App from "./App";
|
||||||
import "./index.scss"; //全局样式
|
import "./index.scss"; //全局样式
|
||||||
|
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}>
|
||||||
@ -16,7 +17,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>
|
||||||
|
@ -12,6 +12,7 @@ import iconRoute from "../../assets/images/commen/icon-route.png";
|
|||||||
import { studyTimeFormat } from "../../utils/index";
|
import { studyTimeFormat } from "../../utils/index";
|
||||||
|
|
||||||
const IndexPage = () => {
|
const IndexPage = () => {
|
||||||
|
document.title = "首页";
|
||||||
const systemConfig = useSelector((state: any) => state.systemConfig.value);
|
const systemConfig = useSelector((state: any) => state.systemConfig.value);
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
const [tabKey, setTabKey] = useState(0);
|
const [tabKey, setTabKey] = useState(0);
|
||||||
|
@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
const LatestLearnPage = () => {
|
const LatestLearnPage = () => {
|
||||||
|
document.title = "最近学习";
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const systemConfig = useSelector((state: any) => state.systemConfig.value);
|
const systemConfig = useSelector((state: any) => state.systemConfig.value);
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user