index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * 全站路由配置
  3. *
  4. * 建议:
  5. * 1. 代码中路由统一使用name属性跳转(不使用path属性)
  6. */
  7. import Vue from 'vue'
  8. import Router from 'vue-router'
  9. Vue.use(Router)
  10. // 开发环境不使用懒加载, 因为懒加载页面太多的话会造成webpack热更新太慢, 所以只有生产环境使用懒加载
  11. const _import = require('./import-' + process.env.NODE_ENV)
  12. // 全局路由(无需嵌套上左右整体布局)
  13. const globalRoutes = [
  14. { path: '/404', component: _import('common/404'), name: '404', meta: { title: '404未找到' } }
  15. ]
  16. // 参猫
  17. export const toolsRoutes = [
  18. {
  19. path: '/tools-analyze',
  20. component: _import('modules/tools/tools-analyze'),
  21. name: 'toolsAnalyze',
  22. meta: { title: '任意竞品透析' }
  23. },
  24. {
  25. path: '/tools-credit',
  26. component: _import('modules/tools/tools-credit'),
  27. name: 'toolsCredit',
  28. meta: { title: '淘宝极速验号' }
  29. },
  30. {
  31. path: '/tools-online',
  32. component: _import('modules/tools/tools-online'),
  33. name: 'toolsOnline',
  34. meta: { title: '在线指数还原' }
  35. },
  36. {
  37. path: '/tools-ordersearch',
  38. component: _import('modules/tools/tools-ordersearch'),
  39. name: 'toolsOrdersearch',
  40. meta: { title: '淘客订单查询' }
  41. },
  42. {
  43. path: '/tools-starkeysearch',
  44. component: _import('modules/tools/tools-starkeysearch'),
  45. name: 'toolsStarkeysearch',
  46. meta: { title: '淘宝下拉框选词' }
  47. },
  48. {
  49. path: '/tools-pricetrend',
  50. component: _import('modules/tools/tools-pricetrend'),
  51. name: 'toolsPricetrend',
  52. meta: { title: '价格走势' }
  53. },
  54. {
  55. path: '/tools-shopinfo',
  56. component: _import('modules/tools/tools-shopinfo'),
  57. name: 'toolsShopinfo',
  58. meta: { title: '店铺信息查询' }
  59. },
  60. {
  61. path: '/tools-feedback',
  62. component: _import('modules/tools/tools-feedback'),
  63. name: 'toolsFeedback',
  64. meta: { title: '商品评论查询' }
  65. },
  66. {
  67. path: '/tools-productinfo',
  68. component: _import('modules/tools/tools-productinfo'),
  69. name: 'toolsProductinfo',
  70. meta: { title: '商品信息查询' }
  71. },
  72. {
  73. path: '/tools-productaskinfo',
  74. component: _import('modules/tools/tools-productaskinfo'),
  75. name: 'toolsProductaskinfo',
  76. meta: { title: '商品问大家' }
  77. },
  78. {
  79. path: '/tools-promote',
  80. component: _import('modules/tools/tools-promote'),
  81. name: 'toolsPromote',
  82. meta: { title: '淘宝卡首屏' }
  83. }
  84. ]
  85. // 个人中心
  86. const mineRoutes = [
  87. {
  88. path: '/mine',
  89. component: _import('modules/mine/index'),
  90. children: [
  91. {
  92. path: '',
  93. component: _import('modules/mine/user'),
  94. name: 'mine',
  95. meta: {
  96. title: '个人中心',
  97. isTab: true
  98. }
  99. },
  100. {
  101. path: '/order-check-order',
  102. component: _import('modules/mine/order/order-check-order'),
  103. name: 'orderCheckOrder',
  104. meta: {
  105. title: '订单查询',
  106. isTab: true
  107. }
  108. },
  109. {
  110. path: '/order-check-package',
  111. component: _import('modules/mine/order/order-check-package'),
  112. name: 'orderCheckPackage',
  113. meta: {
  114. title: '包裹查询',
  115. isTab: true
  116. }
  117. },
  118. {
  119. path: '/pay-check',
  120. component: _import('modules/mine/pay/pay-check'),
  121. name: 'payCheck',
  122. meta: {
  123. title: '充值',
  124. isTab: true,
  125. isUseCache: false,
  126. keepAlive: true
  127. }
  128. },
  129. {
  130. path: '/pay-wallet',
  131. component: _import('modules/mine/pay/pay-wallet'),
  132. name: 'payWallet',
  133. meta: {
  134. title: '我的钱包',
  135. isTab: true,
  136. isUseCache: false,
  137. keepAlive: true
  138. }
  139. }
  140. ]
  141. }
  142. ]
  143. // 礼品商城
  144. const mallRoutes = [
  145. {
  146. path: '/mall',
  147. component: _import('modules/mall/index'),
  148. name: 'mall',
  149. meta: {
  150. title: '礼品商城',
  151. isUseCache: false
  152. }
  153. },
  154. {
  155. path: '/mall/goods-detail/:goodsId',
  156. component: _import('modules/mall/goods-detail'),
  157. name: 'goodsDetail',
  158. meta: {
  159. title: '商品详情',
  160. isUseCache: false
  161. }
  162. },
  163. {
  164. path: '/mall/goods-order/:goodsId',
  165. component: _import('modules/mall/goods-order'),
  166. name: 'goodsDetail',
  167. meta: {
  168. title: '确认订单',
  169. isUseCache: false
  170. }
  171. }
  172. ]
  173. // 主入口路由(需嵌套上左右整体布局)
  174. const mainRoutes = {
  175. path: '/',
  176. component: _import('main'),
  177. name: 'main',
  178. redirect: { name: 'home' },
  179. meta: { title: '主入口整体布局' },
  180. children: [
  181. // 通过meta对象设置路由展示方式
  182. // 1. isTab: 是否通过tab展示内容, true: 是, false: 否
  183. // 2. iframeUrl: 是否通过iframe嵌套展示内容, '以http[s]://开头': 是, '': 否
  184. // 提示: 如需要通过iframe嵌套展示内容, 但不通过tab打开, 请自行创建组件使用iframe处理!
  185. { path: '/login', component: _import('modules/account/login'), name: 'login', meta: { title: '登录' } },
  186. { path: '/register', component: _import('modules/account/register'), name: 'register', meta: { title: '注册' } },
  187. { path: '/home', component: _import('common/home'), name: 'home', meta: { title: '首页', isTab: true } },
  188. ...toolsRoutes,
  189. ...mineRoutes,
  190. ...mallRoutes
  191. ]
  192. }
  193. const router = new Router({
  194. mode: 'history',
  195. scrollBehavior (to, from, savedPosition) {
  196. if (to.hash) {
  197. return {
  198. selector: to.hash
  199. }
  200. }
  201. // keep-alive 返回缓存页面后记录浏览位置
  202. if (savedPosition && to.meta.keepAlive) {
  203. return savedPosition
  204. }
  205. // 异步滚动操作
  206. return new Promise((resolve) => {
  207. setTimeout(() => {
  208. resolve({ x: 0, y: 1 })
  209. }, 0)
  210. })
  211. },
  212. isAddDynamicMenuRoutes: false, // 是否已经添加动态(菜单)路由
  213. routes: globalRoutes.concat(mainRoutes)
  214. })
  215. router.beforeEach((to, from, next) => {
  216. next()
  217. })
  218. export default router