index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. Vue.use(Router)
  4. const pcRouter = new Router({
  5. routes: [
  6. {
  7. path: '/',
  8. alias: [
  9. '/user/:id',
  10. '/login',
  11. '/other/:id',
  12. '/me',
  13. '/editMe',
  14. '/editInfo/:type',
  15. '/groupSet/:id',
  16. '/invite/:inviteType',
  17. '/packetSend',
  18. '/packetGet/:id',
  19. '/search'
  20. ],
  21. name: 'noChat',
  22. component: resolve => {
  23. require(['@/components/chatRoom/noChat.vue'], resolve)
  24. }
  25. },
  26. {
  27. path: '/group/:id',
  28. name: 'groupChat',
  29. component: resolve => {
  30. require(['@/components/chatRoom/chatRoom.vue'], resolve)
  31. }
  32. },
  33. {
  34. path: '/pm/:id',
  35. name: 'pmChat',
  36. component: resolve => {
  37. require(['@/components/chatRoom/chatRoom.vue'], resolve)
  38. }
  39. },
  40. {
  41. path: '/hotGroup',
  42. name: 'hotGroup',
  43. component: resolve => {
  44. require(['@/components/hotGroup/hotGroup.vue'], resolve)
  45. }
  46. }
  47. ]
  48. })
  49. const h5Router = new Router({
  50. routes: [
  51. {
  52. path: '/',
  53. alias: '/user/:id',
  54. name: 'chatList',
  55. component: resolve => {
  56. require(['@/pages/h5/view/chatList.vue'], resolve)
  57. }
  58. },
  59. {
  60. path: '/login',
  61. name: 'login',
  62. component: resolve => {
  63. require(['@/pages/h5/view/login.vue'], resolve)
  64. }
  65. },
  66. {
  67. path: '/other/:id',
  68. name: 'aboutOther',
  69. component: resolve => {
  70. require(['@/pages/h5/view/aboutOther.vue'], resolve)
  71. }
  72. },
  73. {
  74. path: '/me',
  75. name: 'aboutMe',
  76. component: resolve => {
  77. require(['@/pages/h5/view/aboutMe.vue'], resolve)
  78. }
  79. },
  80. {
  81. path: '/editMe',
  82. name: 'editMe',
  83. component: resolve => {
  84. require(['@/pages/h5/view/editMe.vue'], resolve)
  85. }
  86. },
  87. {
  88. path: '/editInfo/:type/:id?',
  89. name: 'editInfo',
  90. component: resolve => {
  91. require(['@/pages/h5/view/editInfo.vue'], resolve)
  92. }
  93. },
  94. {
  95. path: '/group/:id',
  96. name: 'groupChat',
  97. component: resolve => {
  98. require(['@/pages/h5/view/chatRoom.vue'], resolve)
  99. }
  100. },
  101. {
  102. path: '/groupSet/:id',
  103. name: 'groupSet',
  104. component: resolve => {
  105. require(['@/pages/h5/view/chatSet.vue'], resolve)
  106. }
  107. },
  108. {
  109. path: '/pm/:id',
  110. name: 'pmChat',
  111. component: resolve => {
  112. require(['@/pages/h5/view/chatRoom.vue'], resolve)
  113. }
  114. },
  115. {
  116. path: '/invite/:inviteType/:id?',
  117. name: 'invite',
  118. component: resolve => {
  119. require(['@/pages/h5/view/invite.vue'], resolve)
  120. }
  121. },
  122. {
  123. path: '/search',
  124. name: 'search',
  125. component: resolve => {
  126. require(['@/pages/h5/view/search.vue'], resolve)
  127. }
  128. }
  129. ]
  130. })
  131. h5Router.beforeEach((to, from, next) => {
  132. if (to.path !== '/login') {
  133. let userId = localStorage.getItem('user_id')
  134. let token = localStorage.getItem('token')
  135. if (userId && token) {
  136. next()
  137. } else {
  138. next('/login')
  139. }
  140. } else {
  141. next()
  142. }
  143. })
  144. export { h5Router, pcRouter }