index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import LevelRouter from './levelRouter'
  4. import ApplyRouter from './applyRouter'
  5. import AdapayRouter from './adapayRouter'
  6. Vue.use(Router)
  7. let defaultRouter = [
  8. {
  9. path: '/',
  10. redirect: {
  11. name: 'signUp'
  12. }
  13. }, {
  14. path: "/levelMusic",
  15. name: "levelMusic",
  16. component: () =>
  17. import( /* webpackChunkName: "LevelMusic" */ "@/views/LevelMusic"),
  18. meta: {
  19. description: "音乐考级",
  20. weight: 1 // 页面权重
  21. }
  22. }, {
  23. path: "/paymentResult",
  24. name: "paymentResult",
  25. component: () =>
  26. import( /* webpackChunkName: "PaymentResult" */ "@/views/PaymentResult"),
  27. meta: {
  28. description: "支付结果",
  29. weight: 2 // 页面权重
  30. }
  31. }
  32. ]
  33. defaultRouter = defaultRouter.concat(LevelRouter)
  34. .concat(ApplyRouter)
  35. .concat(AdapayRouter)
  36. const router = new Router({
  37. // mode: 'history',
  38. // base: process.env.BASE_URL,
  39. routes: defaultRouter,
  40. scrollBehavior () {
  41. return { x: 0, y: 0 }
  42. }
  43. })
  44. router.onError((error) => {
  45. const pattern = /Loading chunk (\d)+ failed/g;
  46. const isChunkLoadFailed = error.message.match(pattern);
  47. const targetPath = router.history.pending.fullPath;
  48. if (isChunkLoadFailed) {
  49. router.replace(targetPath);
  50. }
  51. })
  52. export default router