router.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. export default ({ app, context, req, 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('before Route Path', window.__NUXT__.routePath)
  8. console.log("app.router.options.routes", app.router.options.routes)
  9. if (isKaifain) {
  10. window.__NUXT__.routePath = app.context.route.path.replace(/^\/kaifain/, '/')
  11. let kaifainIndex = app.router.options.routes.filter(v => v.name === 'kaifain')[ 0 ]
  12. let kaifainDetail = app.router.options.routes.filter(v => v.name === 'kaifain-detail-tid')[ 0 ]
  13. let kaifainCaseDetail = app.router.options.routes.filter(v => v.name === 'kaifain-case-tid')[ 0 ]
  14. let kaifainAdd = app.router.options.routes.filter(v => v.name === 'kaifain-add')[ 0 ]
  15. let kaifainPreview = app.router.options.routes.filter(v => v.name === 'kaifain-preview')[ 0 ]
  16. let kaifainPreviewCase = app.router.options.routes.filter(v => v.name === 'kaifain-previewCase')[ 0 ]
  17. let kaifainIndexNow = {
  18. name: 'kaifain_$',
  19. path: '/*',
  20. component: kaifainIndex.component
  21. }
  22. let kaifainDetailNow = {
  23. name: 'kaifainSeoDetails_$',
  24. path: '/s/:tid',
  25. component: kaifainDetail.component
  26. }
  27. let kaifainCaseDetailNow = {
  28. name: 'kaifainCaseSeoDetails_$',
  29. path: '/d/:tid',
  30. component: kaifainCaseDetail.component
  31. }
  32. let kaifainAddNow = {
  33. name: 'kaifainAdd_$',
  34. path: '/add',
  35. component: kaifainAdd.component
  36. }
  37. let kaifainPreviewNow = {
  38. name: 'kaifainPreview_$',
  39. path: '/preview',
  40. component: kaifainPreview.component
  41. }
  42. let kaifainPreviewCaseNow = {
  43. name: 'kaifainPreviewCase_$',
  44. path: '/previewCase',
  45. component: kaifainPreviewCase.component
  46. }
  47. let kaifainOrderList = [ kaifainPreviewCaseNow,
  48. kaifainPreviewNow,
  49. kaifainAddNow,
  50. kaifainCaseDetailNow,
  51. kaifainDetailNow,
  52. kaifainIndexNow
  53. ]
  54. try {
  55. app.router.options.routes.unshift(...kaifainOrderList)
  56. app.router.matcher.addRoutes(kaifainOrderList)
  57. } catch ( e ) {
  58. console.log(e)
  59. }
  60. }
  61. if (isJishuin) {
  62. window.__NUXT__.routePath = app.context.route.path.replace(/^\/jishuin/, '/')
  63. let jishuinCIndex = app.router.options.routes.filter(v => v.name === "user-collect_article-id-type")[ 0 ]
  64. let jishuinCType = app.router.options.routes.filter(v => v.name === "user-collect_article-id-type")[ 0 ]
  65. let jishuinUIndex = app.router.options.routes.filter(v => v.name === "user-id-type")[ 0 ]
  66. let jishuinUType = app.router.options.routes.filter(v => v.name === "user-id-type")[ 0 ]
  67. let jishuinU = {
  68. name: 'jishuinSeoU_$',
  69. path: '/u/:id',
  70. component: jishuinUIndex.component
  71. }
  72. let jishuinUT = {
  73. name: 'jishuinSeoUType_$',
  74. path: '/u/:id/:type',
  75. component: jishuinUType.component
  76. }
  77. let jishuinC = {
  78. name: 'jishuinSeoC_$',
  79. path: '/c/:id',
  80. component: jishuinCIndex.component
  81. }
  82. let jishuinCT = {
  83. name: 'jishuinSeoCT_$',
  84. path: '/c/:id/:type',
  85. component: jishuinCType.component
  86. }
  87. let jishuinOrderList = [
  88. jishuinCT, jishuinC, jishuinUT, jishuinU
  89. ]
  90. try {
  91. app.router.options.routes.unshift(...jishuinOrderList)
  92. app.router.matcher.addRoutes(jishuinOrderList)
  93. } catch ( e ) {
  94. console.log(e)
  95. }
  96. }
  97. if (isJob) {
  98. window.__NUXT__.routePath = app.context.route.path.replace(/^\/job/, '/')
  99. let jobIndex = app.router.options.routes.filter(v => v.name === 'job')[ 0 ]
  100. let jobDetail = app.router.options.routes.filter(v => v.name === 'job-detail-id')[ 0 ]
  101. let jobIndexNow = {
  102. name: jobIndex.name,
  103. path: '/*',
  104. component: jobIndex.component
  105. }
  106. let jobDetailNow = {
  107. name: jobDetail.name,
  108. path: '/d/:id?',
  109. component: jobDetail.component
  110. }
  111. let jobOrderList = [
  112. jobDetailNow, jobIndexNow
  113. ]
  114. try {
  115. app.router.options.routes.unshift(...jobOrderList)
  116. app.router.matcher.addRoutes(jobOrderList)
  117. } catch ( e ) {
  118. console.log(e)
  119. }
  120. }
  121. console.log('router', app.router)
  122. app.router.beforeEach((to, from, next) => {
  123. console.log("beforeEach", to, from)
  124. next()
  125. })
  126. }
  127. }