index.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import NProgress from 'nprogress'
  4. import Cookies from 'js-cookie'
  5. Vue.use(VueRouter)
  6. const router = new VueRouter({
  7. routes: [{
  8. path: '/login',
  9. name: 'Login',
  10. component: () => import('@/views/login'),
  11. meta: {title: '登录'}
  12. }, {
  13. path: '/logout',
  14. name: 'Logout',
  15. component: () => import('@/views/logout'),
  16. meta: {title: '退出登录'}
  17. }, {
  18. path: '/',
  19. redirect: '/login'
  20. }, {
  21. path: '/data-market/main',
  22. component: () => import('@/views/main'),
  23. children: [{
  24. path: '/data-market/main',
  25. name: 'DataMarketIndex',
  26. meta: {title: '数据大盘'}
  27. }]
  28. },
  29. {
  30. path: '/system',
  31. component: () => import('@/views/main'),
  32. children: [{
  33. path: '/system/data-dict',
  34. name: 'dataDict',
  35. component: () => import('@/views/system/dataDict/list'),
  36. meta: {title: '系统管理 - 数据字典'}
  37. },
  38. {
  39. path:'/system/account',
  40. name:'AccountIndex',
  41. component: () => import('@/views/system/account/list'),
  42. meta: {title: '账号管理'}
  43. },
  44. {
  45. path: '/system/level',
  46. name: 'level',
  47. component: () => import('@/views/system/level/list'),
  48. meta: {title: '系统管理 - 关卡管理'}
  49. },
  50. {
  51. path: '/system/level/detail',
  52. name: 'levelDetail',
  53. component: () => import('@/views/system/level/detail'),
  54. meta: {title: '系统管理 - 题库管理'}
  55. }]
  56. }]
  57. })
  58. let URL_WHITE_TOKEN_LIST = [
  59. '/login'
  60. ]
  61. router.beforeEach((to, from, next) => {
  62. NProgress.start() // 每次切换页面时,调用进度条
  63. next()
  64. // let token = Cookies.get('token')
  65. // if (token) {
  66. // if (to.matched.length === 0) { // 匹配前往的路由不存在
  67. // from.name ? next({name: from.name}) : next('/error') // 判断此跳转路由的来源路由是否存在,存在的情况跳转到来源路由,否则跳转到404页面
  68. // } else {
  69. // next()
  70. // }
  71. // } else {
  72. // if (URL_WHITE_TOKEN_LIST.indexOf(to.path) !== -1) {
  73. // next()
  74. // } else {
  75. // next(`/login?redirect=${to.path}`)
  76. // }
  77. // }
  78. })
  79. router.afterEach(() => {
  80. NProgress.done() // 在即将进入新的页面组件前,关闭掉进度条
  81. })
  82. export default router