index.js 3.9 KB

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