index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. import { updateWechatToken, updateInviteId } from '@/utils'
  4. Vue.use(VueRouter)
  5. const _import = require('./import-' + process.env.NODE_ENV)
  6. const routes = [
  7. // {
  8. // path: '*',
  9. // redirect: '/404'
  10. // },
  11. {
  12. path: '/404',
  13. name: '404',
  14. component: _import('page/404/index')
  15. },
  16. {
  17. path: '/',
  18. component: _import('views/marketing/index'),
  19. children: [
  20. {
  21. path: '', // 省钱
  22. name: 'MarketingSave',
  23. component: _import('views/marketing/save/index'),
  24. meta: {
  25. showTabbar: true,
  26. isUseCache: false,
  27. keepAlive: true
  28. }
  29. },
  30. {
  31. path: '/return', // 返钱
  32. name: 'MarketingReturn',
  33. component: _import('views/marketing/return/index'),
  34. meta: {
  35. showTabbar: true,
  36. isUseCache: false,
  37. keepAlive: true
  38. }
  39. },
  40. {
  41. path: '/make', // 赚钱
  42. name: 'MarketingMake',
  43. component: _import('views/marketing/make/index'),
  44. meta: {
  45. showTabbar: true,
  46. isUseCache: false,
  47. keepAlive: true
  48. }
  49. }
  50. ]
  51. },
  52. {
  53. path: '/invite', // 我的
  54. name: 'Invite',
  55. component: _import('views/invite/index'),
  56. meta: {
  57. showTabbar: true,
  58. isUseCache: false,
  59. keepAlive: true
  60. }
  61. },
  62. {
  63. path: '/mine', // 我的
  64. name: 'Mine',
  65. component: _import('views/mine/index'),
  66. meta: {
  67. showTabbar: true,
  68. isUseCache: false,
  69. keepAlive: true
  70. }
  71. },
  72. {
  73. path: '/recommend', // 分享海报
  74. name: 'Recommend',
  75. component: _import('views/recommend/index'),
  76. meta: {
  77. isUseCache: false,
  78. keepAlive: false
  79. }
  80. },
  81. {
  82. path: '/wallet', // 我的钱包
  83. name: 'Wallet',
  84. component: _import('views/wallet/index'),
  85. meta: {
  86. isUseCache: false,
  87. keepAlive: false
  88. }
  89. },
  90. {
  91. path: '/withdrawCash', // 提现
  92. name: 'WithdrawCash',
  93. component: _import('views/withdrawCash/index'),
  94. meta: {
  95. isUseCache: false,
  96. keepAlive: true
  97. }
  98. },
  99. {
  100. path: '/bill', // 收支明细
  101. name: 'Bill',
  102. component: _import('views/bill/index'),
  103. meta: {
  104. isUseCache: false,
  105. keepAlive: true
  106. }
  107. },
  108. {
  109. path: '/order', // 下单记录
  110. name: 'Order',
  111. component: _import('views/order/index'),
  112. meta: {
  113. isUseCache: false,
  114. keepAlive: true
  115. }
  116. },
  117. {
  118. path: '/fans', // 粉丝
  119. name: 'Fans',
  120. component: _import('views/fans/index'),
  121. meta: {
  122. isUseCache: false,
  123. keepAlive: true
  124. }
  125. },
  126. {
  127. path: '/paymentCode', // 支付码
  128. name: 'PaymentCode',
  129. component: _import('views/paymentCode/index'),
  130. meta: {
  131. isUseCache: false,
  132. keepAlive: false
  133. }
  134. },
  135. {
  136. path: '/shareMiddle', // 分享中间页
  137. name: 'ShareMiddle',
  138. component: _import('views/shareMiddle/index'),
  139. meta: {
  140. isUseCache: false,
  141. keepAlive: false
  142. }
  143. },
  144. {
  145. path: '/category', // 分类
  146. component: _import('views/category/index'),
  147. children: [
  148. {
  149. path: '',
  150. name: 'CategoryIndex',
  151. component: _import('views/category/index/index'),
  152. meta: {
  153. showTabbar: true,
  154. isUseCache: false,
  155. keepAlive: true
  156. }
  157. },
  158. {
  159. path: '/detail/:source/:goodsId',
  160. name: 'CategoryDetail',
  161. component: _import('views/category/detail/index'),
  162. props: (route) => ({
  163. source: route.params.source,
  164. goodsId: route.params.goodsId
  165. })
  166. }
  167. ]
  168. },
  169. {
  170. path: '/search', // 搜索
  171. name: 'Search',
  172. component: _import('views/search/index'),
  173. meta: {
  174. isUseCache: false,
  175. keepAlive: true
  176. }
  177. }
  178. ]
  179. const router = new VueRouter({
  180. mode: 'history',
  181. routes,
  182. scrollBehavior (to, from, savedPosition) {
  183. if (to.hash) {
  184. return {
  185. selector: to.hash
  186. }
  187. }
  188. // keep-alive 返回缓存页面后记录浏览位置
  189. if (savedPosition && to.meta.keepAlive) {
  190. return savedPosition
  191. }
  192. // 异步滚动操作
  193. return new Promise((resolve) => {
  194. setTimeout(() => {
  195. resolve({ x: 0, y: 1 })
  196. }, 0)
  197. })
  198. }
  199. })
  200. const originalPush = VueRouter.prototype.push
  201. VueRouter.prototype.push = function push (location, onResolve, onReject) {
  202. if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  203. return originalPush.call(this, location).catch(err => err)
  204. }
  205. router.beforeEach((to, from, next) => {
  206. updateWechatToken()
  207. updateInviteId()
  208. next()
  209. })
  210. export default router