22 lines
389 B
JavaScript
22 lines
389 B
JavaScript
import router from './index'
|
|
import store from '@/store/index'
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
// 判断是否需要登录
|
|
if (to.meta.requireAuth) {
|
|
// 判断是否登录
|
|
if (store.state.user.token) {
|
|
next()
|
|
} else {
|
|
next({
|
|
path: '/login',
|
|
query: {
|
|
redirect: to.fullPath
|
|
}
|
|
})
|
|
}
|
|
} else {
|
|
next()
|
|
}
|
|
})
|