You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
528 B
22 lines
528 B
export default ({ app }) => {
|
|
app.router.beforeEach((to, from, next) => {
|
|
const { token, userInfo } = app.store.state;
|
|
if (token) {
|
|
if (Object.keys(userInfo).length === 0) {
|
|
app.store.dispatch("getUserInfo");
|
|
}
|
|
next();
|
|
return;
|
|
}
|
|
|
|
// 未登录打开需要登录的页面,跳首页
|
|
const needLoginPage = [/\/account/, /\/cart/];
|
|
const result = needLoginPage.some((item) => item.test(to.path));
|
|
if (result) {
|
|
next("/");
|
|
return;
|
|
}
|
|
next();
|
|
});
|
|
};
|