index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. import AppRouter from './appRouter'
  7. Vue.use(Router)
  8. let defaultRouter = [{
  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. path: "/downLoad",
  33. name: "downLoad",
  34. component: () =>
  35. import( /* webpackChunkName: "DownLoad" */ "@/views/DownLoad"),
  36. meta: {
  37. description: "支付结果",
  38. weight: 2 // 页面权重
  39. }
  40. }]
  41. defaultRouter = defaultRouter.concat(LevelRouter)
  42. .concat(ApplyRouter)
  43. .concat(AdapayRouter)
  44. .concat(AppRouter)
  45. const router = new Router({
  46. // mode: 'history',
  47. // base: process.env.BASE_URL,
  48. routes: defaultRouter,
  49. scrollBehavior() {
  50. return {
  51. x: 0,
  52. y: 0
  53. }
  54. }
  55. })
  56. router.onError((error) => {
  57. const pattern = /Loading chunk (\d)+ failed/g;
  58. const isChunkLoadFailed = error.message.match(pattern);
  59. const targetPath = router.history.pending.fullPath;
  60. if (isChunkLoadFailed) {
  61. router.replace(targetPath);
  62. }
  63. })
  64. const originalPush = Router.prototype.push
  65. Router.prototype.push = function(location) {
  66. return originalPush.call(this, location).catch(err => err)
  67. }
  68. export default router