index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. // 加载条
  4. import NProgress from 'nprogress'
  5. import 'nprogress/nprogress.css'
  6. import VueAMap from 'vue-amap';
  7. Vue.use(VueRouter);
  8. // Vue.use(VueAMap);
  9. // VueAMap.initAMapApiLoader({
  10. // key: 'your amap key',
  11. // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  12. // // 默认高德 sdk 版本为 1.4.4
  13. // v: '1.4.4'
  14. // });
  15. const routes = [
  16. {
  17. path: '/',
  18. component: () => import( '../views/Index.vue'),
  19. children: [
  20. {
  21. path: '/',
  22. name: 'Main',
  23. component: () => import('@/views/Wait.vue'),
  24. meta: {
  25. title: "等待",
  26. clmid: "1",
  27. }
  28. },{
  29. path: '/main',
  30. name: 'Main',
  31. component: () => import('@/views/Main.vue'),
  32. meta: {
  33. title: "团课",
  34. clmid: "1",
  35. }
  36. },{
  37. path: '/rank',
  38. name: 'Rank',
  39. component: () => import('@/views/Rank.vue'),
  40. meta: {
  41. title: "排名",
  42. clmid: "2",
  43. }
  44. },{
  45. path: '/wait',
  46. name: 'Wait',
  47. component: () => import('@/views/Wait.vue'),
  48. meta: {
  49. title: "等待",
  50. clmid: "2",
  51. }
  52. },{
  53. path: '/pk',
  54. name: 'pk',
  55. component: () => import('@/views/pk.vue'),
  56. meta: {
  57. title: "pk",
  58. clmid: "3",
  59. }
  60. },{
  61. path: '/gropePk',
  62. name: 'gropePk',
  63. component: () => import('@/views/gropePk.vue'),
  64. meta: {
  65. title: "gropePk",
  66. clmid: "4",
  67. }
  68. },{
  69. path: '/2pkRank',
  70. name: '2pkRank',
  71. component: () => import('@/views/2pkRank.vue'),
  72. meta: {
  73. title: "2pkRank",
  74. clmid: "5",
  75. }
  76. },{
  77. path: '/3pk',
  78. name: '3pk',
  79. component: () => import('@/views/3pk.vue'),
  80. meta: {
  81. title: "3pk",
  82. clmid: "6",
  83. }
  84. },{
  85. path: '/test',
  86. name: 'test',
  87. component: () => import('@/views/test.vue'),
  88. meta: {
  89. title: "test",
  90. clmid: "999",
  91. }
  92. },
  93. ]
  94. }, {
  95. path: '*',
  96. name: '404',
  97. component: () => import( '../views/404.vue')
  98. },
  99. ]
  100. const originalPush = VueRouter.prototype.push;
  101. VueRouter.prototype.push = function push(location) {
  102. return originalPush.call(this, location).catch(err => err)
  103. };
  104. const router = new VueRouter({
  105. // mode: 'history',
  106. mode: 'hash',
  107. base: process.env.BASE_URL,
  108. routes
  109. });
  110. // 路由守卫
  111. router.beforeEach((to,from,next)=>{
  112. NProgress.start();
  113. const isLogin = localStorage.token? true : false;
  114. if(to.path == '/login' || to.path == '/register'){//'login'和'register'相当于是路由白名单
  115. next();
  116. }else{
  117. //如果token存在,就正常跳转,如果不存在,则说明未登陆,则跳转到'login'
  118. // isLogin? next() : next("/login");
  119. next();
  120. }
  121. });
  122. router.afterEach(() => {
  123. NProgress.done()
  124. });
  125. export default router