From df2ab806c66c8c6012c58a62aae75c4962d069cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com>
Date: Mon, 17 Apr 2023 11:20:54 +0800
Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=BB=9A=E5=88=B0=E5=88=B0?=
=?UTF-8?q?=E9=A1=B6=E9=83=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/AutoTop.ts | 12 ++++++++++++
src/main.tsx | 5 ++++-
src/pages/index/index.tsx | 1 +
src/pages/latest-learn/index.tsx | 1 +
4 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 src/AutoTop.ts
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);