You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
duoji-frontend/src/router/index.js

105 lines
2.4 KiB
JavaScript

6 years ago
import Vue from 'vue'
import VueRouter from 'vue-router'
const files = require.context('@/views', true, /-router\.js$/)
let allRouter = [];
// 匹配成功的名字数组
files.keys().map(key => {
allRouter = allRouter.concat(files(key).default)
})
allRouter.sort((a, b) => {
return a.meta.sort - b.meta.sort
})
console.log(allRouter)
Vue.use(VueRouter)
// 避免冗余导航 (重复点击菜单栏报错问题)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const routes = [{
6 years ago
path: '/',
redirect: {
name: 'guide'
},
6 years ago
component: () => import('@/views/main'),
children: [{
path: 'realTime',
name: 'realTime',
meta: {
icon: 'global',
name: '实时监控'
},
component: () => import('@/views/realTime/index')
}, {
path: 'history',
name: 'history',
meta: {
icon: 'cloud',
name: '历史监控'
},
component: () => import('@/views/history/index')
}, {
path: 'center',
name: 'center',
meta: {
name: '个人中心'
},
component: () => import('@/views/center')
}]
},
{
path: '/guide',
name: 'guide',
component: () => import('../views/guide.vue')
},
{
path: '*',
name: '404',
component: () => import('../views/404.vue')
}
6 years ago
]
const router = new VueRouter({
routes
})
router.beforeEach((to, from, next) => {
6 years ago
next()
// let userInfo = JSON.parse(sessionStorage.getItem('userInfo') || '{}')
// // 校验是否登录
// if (userInfo.id) {
// // 匹配不到 404
// if (!to.name) next();
// // 权限
// if (userInfo.permissionList.some((item) => {
// return item.rights === to.name
// })) {
// next()
// } else {
// if (to.name === 'login') {
// next()
// } else {
// Vue.prototype.$message.info('没有权限')
// next(false)
// }
// }
// } else {
// if (to.name === 'login') {
// next()
// } else if (to.name !== 'login') {
// Vue.prototype.$message.info('请先登录')
// next('/login')
// } else {
// next('/login')
// }
// }
6 years ago
})
export default router