1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- import NProgress from 'nprogress'
- import Cookies from 'js-cookie'
- Vue.use(VueRouter)
- const router = new VueRouter({
- routes: [{
- path: '/login',
- name: 'Login',
- component: () => import('@/views/login'),
- meta: {title: '登录'}
- }, {
- path: '/logout',
- name: 'Logout',
- component: () => import('@/views/logout'),
- meta: {title: '退出登录'}
- }, {
- path: '/',
- redirect: '/login'
- }, {
- path: '/data-market/main',
- component: () => import('@/views/main'),
- children: [{
- path: '/data-market/main',
- name: 'DataMarketIndex',
- meta: {title: '数据大盘'}
- }]
- },
- {
- path: '/system',
- component: () => import('@/views/main'),
- children: [{
- path: '/system/data-dict',
- name: 'dataDict',
- component: () => import('@/views/system/dataDict/list'),
- meta: {title: '系统管理 - 数据字典'}
- },
- {
- path:'/system/account',
- name:'AccountIndex',
- component: () => import('@/views/system/account/list'),
- meta: {title: '账号管理'}
- },
- {
- path: '/system/level',
- name: 'level',
- component: () => import('@/views/system/level/list'),
- meta: {title: '系统管理 - 关卡管理'}
- },
- {
- path: '/system/level/detail',
- name: 'levelDetail',
- component: () => import('@/views/system/level/detail'),
- meta: {title: '系统管理 - 题库管理'}
- }]
- }]
- })
- let URL_WHITE_TOKEN_LIST = [
- '/login'
- ]
- router.beforeEach((to, from, next) => {
- NProgress.start() // 每次切换页面时,调用进度条
- next()
- // let token = Cookies.get('token')
- // if (token) {
- // if (to.matched.length === 0) { // 匹配前往的路由不存在
- // from.name ? next({name: from.name}) : next('/error') // 判断此跳转路由的来源路由是否存在,存在的情况跳转到来源路由,否则跳转到404页面
- // } else {
- // next()
- // }
- // } else {
- // if (URL_WHITE_TOKEN_LIST.indexOf(to.path) !== -1) {
- // next()
- // } else {
- // next(`/login?redirect=${to.path}`)
- // }
- // }
- })
- router.afterEach(() => {
- NProgress.done() // 在即将进入新的页面组件前,关闭掉进度条
- })
- export default router
|