index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. path: '/relateGroup',
  49. name: 'relateGroup',
  50. component: resolve => {
  51. require(['@/components/relateGroup/relateGroup.vue'], resolve)
  52. }
  53. }
  54. ]
  55. })
  56. const h5Router = new Router({
  57. routes: [
  58. {
  59. path: '/',
  60. alias: '/user/:id',
  61. name: 'chatList',
  62. component: resolve => {
  63. require(['@/pages/h5/view/chatList.vue'], resolve)
  64. }
  65. },
  66. {
  67. path: '/login',
  68. name: 'login',
  69. component: resolve => {
  70. require(['@/pages/h5/view/login.vue'], resolve)
  71. }
  72. },
  73. {
  74. path: '/loginMee',
  75. name: 'loginMee',
  76. component: resolve => {
  77. require(['@/pages/h5/view/loginMee.vue'], resolve)
  78. }
  79. },
  80. {
  81. path: '/other/:id',
  82. name: 'aboutOther',
  83. component: resolve => {
  84. require(['@/pages/h5/view/aboutOther.vue'], resolve)
  85. }
  86. },
  87. {
  88. path: '/me',
  89. name: 'aboutMe',
  90. component: resolve => {
  91. require(['@/pages/h5/view/aboutMe.vue'], resolve)
  92. }
  93. },
  94. {
  95. path: '/editMe',
  96. name: 'editMe',
  97. component: resolve => {
  98. require(['@/pages/h5/view/editMe.vue'], resolve)
  99. }
  100. },
  101. {
  102. path: '/editInfo/:type/:id?',
  103. name: 'editInfo',
  104. component: resolve => {
  105. require(['@/pages/h5/view/editInfo.vue'], resolve)
  106. }
  107. },
  108. {
  109. path: '/group/:id',
  110. name: 'groupChat',
  111. component: resolve => {
  112. require(['@/pages/h5/view/chatRoom.vue'], resolve)
  113. }
  114. },
  115. {
  116. path: '/groupSet/:id',
  117. name: 'groupSet',
  118. component: resolve => {
  119. require(['@/pages/h5/view/chatSet.vue'], resolve)
  120. }
  121. },
  122. {
  123. path: '/pm/:id',
  124. name: 'pmChat',
  125. component: resolve => {
  126. require(['@/pages/h5/view/chatRoom.vue'], resolve)
  127. }
  128. },
  129. {
  130. path: '/invite/:inviteType/:id?',
  131. name: 'invite',
  132. component: resolve => {
  133. require(['@/pages/h5/view/invite.vue'], resolve)
  134. }
  135. },
  136. {
  137. path: '/search',
  138. name: 'search',
  139. component: resolve => {
  140. require(['@/pages/h5/view/search.vue'], resolve)
  141. }
  142. },
  143. {
  144. path: '/password',
  145. name: 'password',
  146. component: resolve => {
  147. require(['@/pages/h5/view/password.vue'], resolve)
  148. }
  149. },
  150. {
  151. path: '/relateGroup',
  152. name: 'relateGroup',
  153. component: resolve => {
  154. require(['@/components/relateGroup/relateGroup.vue'], resolve)
  155. }
  156. }
  157. ]
  158. })
  159. h5Router.beforeEach((to, from, next) => {
  160. if (to.path !== '/login' && to.path !== '/loginMee') {
  161. let userId = localStorage.getItem('user_id')
  162. let token = localStorage.getItem('token')
  163. if (userId && token) {
  164. next()
  165. } else {
  166. next('/login')
  167. }
  168. } else {
  169. next()
  170. }
  171. })
  172. export { h5Router, pcRouter }