解决已知问题
This commit is contained in:
@@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
import { useUserStore } from '@/stores';
|
||||
|
||||
// 如果有token,就跳转到首页
|
||||
// 如果即将去往的是 /login 页面并且有 token 情况就自动重定向到 /home,否则就跳转
|
||||
const useAuthRedirect = () => {
|
||||
const store = useUserStore();
|
||||
const navigate = useNavigate();
|
||||
@@ -10,8 +10,10 @@ const useAuthRedirect = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const token = store.token;
|
||||
if (token) navigate('/home');
|
||||
}, [location, navigate]);
|
||||
const isGoingToLogin = location.pathname === '/login';
|
||||
|
||||
if (isGoingToLogin && token) navigate('/home');
|
||||
}, [location, navigate, store.token]);
|
||||
};
|
||||
|
||||
export default useAuthRedirect;
|
||||
|
||||
Reference in New Issue
Block a user