feat: 未登录跳首页放入中间件判断 See merge request yanxuan-frontend/shop-pc!74merge-requests/75/head
commit
2c317806a1
@ -0,0 +1,10 @@
|
||||
export default function ({ app, route, redirect }) {
|
||||
if (!app.store.state.token) {
|
||||
// 未登录直接打开需要登录的页面,跳转首页
|
||||
const needLoginPage = [/\/account/, /\/cart/];
|
||||
const result = needLoginPage.some((item) => item.test(route.path));
|
||||
if (result) {
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
export default ({ app }) => {
|
||||
app.router.beforeEach((to, from, next) => {
|
||||
// 获取用户信息
|
||||
const { token, userInfo } = app.store.state;
|
||||
if (token) {
|
||||
if (Object.keys(userInfo).length === 0) {
|
||||
if (token && Object.keys(userInfo).length === 0) {
|
||||
app.store.dispatch("getUserInfo");
|
||||
}
|
||||
next();
|
||||
return;
|
||||
}
|
||||
next();
|
||||
});
|
||||
};
|
||||
|
Loading…
Reference in new issue