Skip to content

Commit

Permalink
fix(admin): 先检查 token 再发送请求,避免两次跳转登录
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed May 30, 2024
1 parent 833c8b8 commit ef1b90a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ const Layout = ({children}) => {
menus: [],
});

// 没有 token 则提前跳转到登录页面
const location = useLocation();
useEffect(() => {
// 没有 token 则提前跳转到登录页面
if (!window.localStorage.getItem('token')) {
$.to(getLoginPath(null, location));
}
}, []);
if (!window.localStorage.getItem('token')) {
$.to(getLoginPath(null, location));
return;
}

const getMenu = async () => {
const {ret} = await $.get('admin-page', {loading: true});
Expand Down

0 comments on commit ef1b90a

Please sign in to comment.