aabbcc/src/router/permission.js
username 8c4bc4485e 1
2024-05-27 19:54:39 +08:00

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()
}
})