Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
router.beforeEach(async (to, from, next) => {
LoadingBar.start()
if (getToken()) {
if (to.name === 'login') {
next('/')
} else {
if (store.getters.loggedIn) {
next()
} else {
try {
await store.dispatch('getUser')
} catch (e) {
LoadingBar.error()
return next(false)
}
next()
}
}
} else if (to.matched.some(r => (r.meta && r.meta.auth))) {
next({
name: 'login',
query: {
redirect: to.path,
},
})
} else {
next()
}
LoadingBar.finish()
}, error => {
LoadingBar.error();
Message.error('请求服务器超时');
return error;
})
}, error => {
LoadingBar.error()
Message.error('请求服务器超时')
return error
})