router.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. export default ({ app, store }) => {
  2. if (process.client) {
  3. const { host } = location || {}
  4. const isKaifain = host.indexOf('kaifain') !== -1
  5. const isJishuin = host.indexOf('jishuin') !== -1
  6. const isJob = host.indexOf('job') !== -1
  7. console.log("app.router.options.routes", app.router.options.routes)
  8. if (isKaifain) {
  9. let kaifainIndex = app.router.options.routes.filter(v => v.name === 'kaifainSeoIndex')[0]
  10. let kaifainDetail = app.router.options.routes.filter(v => v.name === 'kaifainSeoDetail')[0]
  11. let kaifainCaseDetail = app.router.options.routes.filter(v => v.name === 'kaifainCaseSeoDetail')[0]
  12. app.router.options.routes.unshift({
  13. name: 'kaifain_$',
  14. path: '/*',
  15. component: kaifainIndex.component
  16. })
  17. app.router.options.routes.unshift({
  18. name: 'kaifainSeoDetails_$',
  19. path: '/s/:tid',
  20. component: kaifainDetail.component
  21. })
  22. app.router.options.routes.unshift({
  23. name: 'kaifainCaseSeoDetails_$',
  24. path: '/d/:tid',
  25. component: kaifainCaseDetail.component
  26. })
  27. app.router.matcher.addRoutes([{
  28. name: 'kaifainSeoDetails_$',
  29. path: '/s/:tid',
  30. component: () => import('@/pages/kaifain/detail/_tid/index.vue')
  31. }, {
  32. name: 'kaifainCaseSeoDetails_$',
  33. path: '/d/:tid',
  34. component: () => import('@/pages/kaifain/case/_tid.vue')
  35. }])
  36. }
  37. if (isJishuin) {
  38. //合集
  39. app.router.options.routes.unshift({
  40. name: 'jishuinCollectedC',
  41. path: '/c/:id',
  42. component: import('@/pages/user/collect_article/_id/_type.vue')
  43. })
  44. app.router.options.routes.unshift({
  45. name: 'jishuinCollectedCID',
  46. path: '/c/:id/:type',
  47. component: import('@/pages/user/collect_article/_id/_type.vue')
  48. })
  49. app.router.options.routes.unshift({
  50. name: 'jishuinUserU',
  51. path: '/u/:id',
  52. component: import('@/pages/user/_id/_type.vue')
  53. })
  54. app.router.options.routes.unshift({
  55. name: 'jishuinUserUID',
  56. path: '/u/:id/:type',
  57. component: import('@/pages/user/_id/_type.vue')
  58. })
  59. app.router.matcher.addRoutes([{
  60. name: 'jishuinCollectedC',
  61. path: '/c/:id',
  62. component: import('@/pages/user/collect_article/_id/_type.vue')
  63. }])
  64. app.router.matcher.addRoutes([{
  65. name: 'jishuinCollectedCID',
  66. path: '/c/:id/:type',
  67. component: import('@/pages/user/collect_article/_id/_type.vue')
  68. }])
  69. app.router.matcher.addRoutes([{
  70. name: 'jishuinUserU',
  71. path: '/u/:id',
  72. component: import('@/pages/user/_id/_type.vue')
  73. }])
  74. app.router.matcher.addRoutes([{
  75. name: 'jishuinUserUID',
  76. path: '/u/:id/:type',
  77. component: import('@/pages/user/_id/_type.vue')
  78. }])
  79. }
  80. if (isJob) {
  81. app.router.options.routes.unshift({
  82. name: 'jobSeoDetails_$',
  83. path: '/d/:id',
  84. component: () => import('@/pages/job/detail/_id.vue')
  85. })
  86. app.router.options.routes.unshift({
  87. name: 'JobListSeoIndex_$',
  88. path: '/',
  89. component: () => import('@/pages/job/index.vue')
  90. })
  91. app.router.matcher.addRoutes([{
  92. name: 'jobSeoDetails_$',
  93. path: '/d/:id',
  94. component: () => import('@/pages/job/detail/_id.vue')
  95. }, {
  96. name: 'JobListSeoIndex_$',
  97. path: '/',
  98. component: () => import('@/pages/job/index.vue')
  99. }])
  100. }
  101. console.log('router', app.router)
  102. app.router.beforeEach((to, from, next)=> {
  103. console.log("location.href", to, from)
  104. next()
  105. })
  106. }
  107. }