张涛 1 year ago
parent
commit
ffc0b75436
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      src/layouts/AuthLayout/index.jsx

+ 11
- 1
src/layouts/AuthLayout/index.jsx View File

@@ -1,8 +1,10 @@
1
-import React from "react";
1
+import React, { useEffect } from "react";
2 2
 import { Spin } from "antd";
3 3
 import HtmlTitle from "./components/HtmlTitle";
4 4
 // import Main from './Main';
5 5
 import withLogin from "./withLogin";
6
+import { getToken } from "@/utils/token";
7
+import { useNavigate } from "react-router-dom";
6 8
 
7 9
 const Spinner = () => (
8 10
   <div
@@ -18,6 +20,14 @@ const Spinner = () => (
18 20
 );
19 21
 
20 22
 export default (props) => {
23
+  const navigator = useNavigate();
24
+
25
+  const token = getToken();
26
+  useEffect(() => {
27
+    if (!token) {
28
+      navigator("login");
29
+    }
30
+  }, [token]);
21 31
   const RequireLogin = React.lazy(() => {
22 32
     return withLogin(import("./Main"));
23 33
   });