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 eca299d..462a531 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -8,6 +8,7 @@ import { ConfigProvider } from "antd"; import zhCN from "antd/locale/zh_CN"; import App from "./App"; import "./index.scss"; //全局样式 +import AutoScorllTop from "./AutoTop"; ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( @@ -16,7 +17,9 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( theme={{ token: { colorPrimary: "#ff4d4f" } }} > - + + + diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 3308fda..5fb956b 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -12,6 +12,7 @@ import iconRoute from "../../assets/images/commen/icon-route.png"; import { studyTimeFormat } from "../../utils/index"; const IndexPage = () => { + document.title = "首页"; const systemConfig = useSelector((state: any) => state.systemConfig.value); const [loading, setLoading] = useState(false); const [tabKey, setTabKey] = useState(0); diff --git a/src/pages/latest-learn/index.tsx b/src/pages/latest-learn/index.tsx index 7a679a8..6df6a91 100644 --- a/src/pages/latest-learn/index.tsx +++ b/src/pages/latest-learn/index.tsx @@ -8,6 +8,7 @@ import { useNavigate } from "react-router-dom"; import { useSelector } from "react-redux"; const LatestLearnPage = () => { + document.title = "最近学习"; const navigate = useNavigate(); const systemConfig = useSelector((state: any) => state.systemConfig.value); const [loading, setLoading] = useState(false);