解决已知问题

This commit is contained in:
宇阳
2024-08-04 19:20:08 +08:00
parent 5c312aedbd
commit 662e376d72

View File

@@ -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;