router.js 4.6 KB

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