router.js 5.1 KB

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