Former-commit-id: 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 21da16e18630a8b3064f6bdd1b8cdd2c1b760439 [formerly 80fff8f10f84df7860d79293a4203c93c835ab7d [formerly 4058e66ecf06d1121f63f05950c7eba795ef4f43]]]]] Former-commit-id: 193dfc5044ad4be16c9de7ee233eb98a0b7d5090 Former-commit-id: 81588f7befd8834d0a908a0a21c8d51f4f64b0c5 Former-commit-id: 7175bd2c811fb738e3698d0d120e4292363e2315 [formerly e5dbd4dfdb31f6a8474843f57d3242d9d5d6734b] Former-commit-id: a9776650ed2f81a32d47389a04e0d914b6dab62b Former-commit-id: 983a77dffbfbd6c10b6943d953552333ac34f276 Former-commit-id: d582b38c28027aa7caa1a165c5ea457dbba97f8d Former-commit-id: 0b5c23c4b6ac208cc9dfe36b76211351a4b2de06 Former-commit-id: 584fa36572a92cabbb07640ed8ec741cc7a50bf4
54 lines
1.3 KiB
JavaScript
Executable File
54 lines
1.3 KiB
JavaScript
Executable File
import Vue from 'vue'
|
|
import VueRouter from 'vue-router'
|
|
|
|
import util from '@/libs/util.js'
|
|
|
|
// 路由数据
|
|
import routes from './routes'
|
|
|
|
Vue.use(VueRouter)
|
|
|
|
// 导出路由 在 main.js 里使用
|
|
const router = new VueRouter({
|
|
routes
|
|
})
|
|
|
|
/**
|
|
* 路由拦截
|
|
* 权限验证
|
|
*/
|
|
router.beforeEach((to, from, next) => {
|
|
// 验证当前路由所有的匹配中是否需要有登陆验证的
|
|
if (to.matched.some(r => r.meta.requiresAuth)) {
|
|
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
|
|
// 请根据自身业务需要修改
|
|
const token = util.cookies.get('token')
|
|
if (token && token !== 'undefined') {
|
|
next()
|
|
} else {
|
|
// 将当前预计打开的页面完整地址临时存储 登陆后继续跳转
|
|
// 这个 cookie(redirect) 会在登陆后自动删除
|
|
util.cookies.set('redirect', to.fullPath)
|
|
// 没有登陆的时候跳转到登陆界面
|
|
next({
|
|
name: 'login'
|
|
})
|
|
}
|
|
} else {
|
|
// 不需要身份校验 直接通过
|
|
next()
|
|
}
|
|
})
|
|
|
|
router.afterEach(to => {
|
|
// 需要的信息
|
|
const app = router.app
|
|
const { name, params, query } = to
|
|
// 多页控制 打开新的页面
|
|
app.$store.commit('d2admin/page/open', { name, params, query })
|
|
// 更改标题
|
|
util.title(to.meta.title)
|
|
})
|
|
|
|
export default router
|