Files
mes-ui-d2/src/router/index.js
liyang 9fa02a7b60 如果是电脑访问 is-mobile 页面的话 跳转到首页
Former-commit-id: b69892d584c0d90e74afc65f3a0f5aa72d7a8902 [formerly b69892d584c0d90e74afc65f3a0f5aa72d7a8902 [formerly b69892d584c0d90e74afc65f3a0f5aa72d7a8902 [formerly b69892d584c0d90e74afc65f3a0f5aa72d7a8902 [formerly c96c92f194844b48a638d03aea3c3f841a2d4ae0 [formerly 02b02df6ba1d89008d69fb1c029279863b039845]]]]]
Former-commit-id: 7e9989ba1ce54e84804ff3de09dba15d7260222b
Former-commit-id: 3b964378c169dcbe2f9aeaae639ee6120f2f5451
Former-commit-id: 1d2b7d44b33c568d02a42b510b50f8592c2d2c06 [formerly 88d3c50c4664c178e310ec482bfc29c1927922ad]
Former-commit-id: c65f5b27cf2c5ac2c4dbdbc746cd76e7ef61fbb1
Former-commit-id: 792eab1a332813861f486bebadcc759ed2f94fa0
Former-commit-id: 2f2aac48b2895a16071d09a0842e0aacff16d272
Former-commit-id: 28f2651336d25e04d944c3fdd42cd3f1ce3e8a0f
Former-commit-id: 7195e2683708e918a446774c22949d59d5e125b0
2018-07-18 11:18:36 +08:00

59 lines
1.4 KiB
JavaScript
Executable File

import Vue from 'vue'
import VueRouter from 'vue-router'
import Cookies from 'js-cookie'
import util from '@/libs/util.js'
// 路由数据
import routes from './routes'
Vue.use(VueRouter)
let router = new VueRouter({ routes })
/**
* 路由拦截
* 权限验证
*/
router.beforeEach((to, from, next) => {
// 禁止手机访问
if (to.name !== 'is-mobile' && util.isMobile()) {
next({ name: 'is-mobile' })
return
}
// 如果是电脑访问 is-mobile 页面的话 跳转到首页
if (to.name === 'is-mobile' && !util.isMobile()) {
next({ name: 'index' })
return
}
// 验证当前路由所有的匹配中是否需要有登陆验证的
if (to.matched.some(r => r.meta.requiresAuth)) {
// 这里暂时将cookie里是否存有token作为验证是否登陆的条件
// 请根据自身业务需要修改
const token = Cookies.get('token')
if (token && token !== 'undefined') {
next()
} else {
// 没有登陆的时候跳转到登陆界面
next({
name: 'login'
})
}
} else {
// 不需要身份校验 直接通过
next()
}
})
router.afterEach(to => {
// 需要的信息
const app = router.app
const { name, params, query } = to
// 多页控制 打开新的页面
app.$store.commit('d2adminPageOpenNew', { name, params, query })
// 更改标题
util.title(to.meta.title)
})
export default router