auto commit on save
Former-commit-id: e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly 942fc2c1ecb4acadc3ea3263fa98dcb0cc8a8384 [formerly 5a76e04062564d23570aa415dd3aefc68d23e5f6]]]]] Former-commit-id: bd8706af49ef4017e036b4a0db1d291fdebf3b61 Former-commit-id: 6068f9065eb9d80b4e46fc8508ae3e6a0bade5eb Former-commit-id: d7aa5aff751370ac1ce7c8681b70d2f4f6fd679b [formerly 77c021aaf98c021623f641310c007451b8489d81] Former-commit-id: 306eb675bbd8331b4adc95e0db5197c262174ad8 Former-commit-id: 11d9451e600878ce1448b555915a3c73aae37adf Former-commit-id: acaf75124bec8cea6b21ad581d60a660ce0d1cf6 Former-commit-id: 7fedcb8810b5ae39617f62e002bad67d72388460 Former-commit-id: 81cc5e9d1f2c2fe1d15f596994e1b93cd13bf25c
This commit is contained in:
52
src/router/index.js
Executable file
52
src/router/index.js
Executable file
@@ -0,0 +1,52 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
import routers from './routers'
|
||||
|
||||
import util from '@/libs/util.js'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
let router = new VueRouter({ routers })
|
||||
|
||||
/**
|
||||
* 路由拦截
|
||||
* 权限验证
|
||||
*/
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 验证当前路由所有的匹配中是否需要有登陆验证的
|
||||
if (to.matched.some(r => r.meta.requiresAuth)) {
|
||||
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
|
||||
// 请根据自身业务需要修改
|
||||
if (Cookies.get('token')) {
|
||||
next()
|
||||
} else {
|
||||
// 没有登陆的时候跳转到登陆界面
|
||||
next({
|
||||
name: 'login'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// 不需要身份校验 直接通过
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
// TODO: 路由跳转后自动滚动到顶部
|
||||
router.afterEach(to => {
|
||||
// 需要的信息
|
||||
const app = router.app
|
||||
const { name, params, query } = to
|
||||
// dev
|
||||
console.group('router.afterEach')
|
||||
console.log('app: ', app)
|
||||
console.log('name: ', name)
|
||||
console.log('params: ', params)
|
||||
console.log('query: ', query)
|
||||
console.groupEnd()
|
||||
// 多页控制 打开新的页面
|
||||
util.openNewPage(app, name, params, query)
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user