lushuncheng vor 5 Jahren
Ursprung
Commit
ac02aed403
2 geänderte Dateien mit 38 neuen und 31 gelöschten Zeilen
  1. 37 30
      plugins/router.js
  2. 1 1
      plugins/seoRouter.js

+ 37 - 30
plugins/router.js

@@ -1,19 +1,26 @@
-export default ({ app, context, req, store }) => {
-  
+export default ({
+  app,
+  context,
+  req,
+  store
+}) => {
+
   if (process.client) {
-    const { host } = location || {}
+    const {
+      host
+    } = location || {}
     const isKaifain = host.indexOf('kaifain') !== -1
     const isJishuin = host.indexOf('jishuin') !== -1
     const isJob = host.indexOf('job') !== -1
     console.log("app.router.options.routes", app.router.options.routes)
     if (isKaifain) {
       window.__NUXT__.routePath = app.context.route.path.replace(/^\/kaifain/, '')
-      let kaifainIndex = app.router.options.routes.filter(v => v.name === 'kaifain')[ 0 ]
-      let kaifainDetail = app.router.options.routes.filter(v => v.name === 'kaifain-detail-tid')[ 0 ]
-      let kaifainCaseDetail = app.router.options.routes.filter(v => v.name === 'kaifain-case-tid')[ 0 ]
-      let kaifainAdd = app.router.options.routes.filter(v => v.name === 'kaifain-add')[ 0 ]
-      let kaifainPreview = app.router.options.routes.filter(v => v.name === '/kaifain/preview')[ 0 ]
-      let kaifainPreviewCase = app.router.options.routes.filter(v => v.name === '/kaifain-previewCase')[ 0 ]
+      let kaifainIndex = app.router.options.routes.filter(v => v.name === 'kaifain')[0]
+      let kaifainDetail = app.router.options.routes.filter(v => v.name === 'kaifain-detail-tid')[0]
+      let kaifainCaseDetail = app.router.options.routes.filter(v => v.name === 'kaifain-case-tid')[0]
+      let kaifainAdd = app.router.options.routes.filter(v => v.name === 'kaifain-add')[0]
+      let kaifainPreview = app.router.options.routes.filter(v => v.name === '/kaifain/preview')[0]
+      let kaifainPreviewCase = app.router.options.routes.filter(v => v.name === '/kaifain-previewCase')[0]
       let kaifainIndexNow = {
         name: 'kaifain_$',
         path: '/*',
@@ -31,17 +38,17 @@ export default ({ app, context, req, store }) => {
       }
       let kaifainAddNow = {
         name: 'kaifainAdd_$',
-        path: '/d/:tid',
+        path: '/add/',
         component: kaifainAdd.component
       }
       let kaifainPreviewNow = {
         name: 'kaifainPreview_$',
-        path: '/d/:tid',
+        path: '/preview',
         component: kaifainPreview.component
       }
       let kaifainPreviewCaseNow = {
         name: 'kaifainPreviewCase_$',
-        path: '/d/:tid',
+        path: '/previewCase',
         component: kaifainPreviewCase.component
       }
       try {
@@ -56,17 +63,17 @@ export default ({ app, context, req, store }) => {
           kaifainIndexNow, kaifainDetailNow, kaifainCaseDetailNow,
           kaifainAddNow, kaifainPreviewNow, kaifainPreviewCaseNow
         ])
-      } catch ( e ) {
+      } catch (e) {
         console.log(e)
       }
     }
-    
+
     if (isJishuin) {
       window.__NUXT__.routePath = app.context.route.path.replace(/^\/jishuin/, '')
-      let jishuinCIndex = app.router.options.routes.filter(v => v.name === "jishuinCollectedC1")[ 0 ]
-      let jishuinCType = app.router.options.routes.filter(v => v.name === "jishuinCollectedCID1")[ 0 ]
-      let jishuinUIndex = app.router.options.routes.filter(v => v.name === "jishuinUserU1")[ 0 ]
-      let jishuinUType = app.router.options.routes.filter(v => v.name === "jishuinUserUID1")[ 0 ]
+      let jishuinCIndex = app.router.options.routes.filter(v => v.name === "jishuinCollectedC1")[0]
+      let jishuinCType = app.router.options.routes.filter(v => v.name === "jishuinCollectedCID1")[0]
+      let jishuinUIndex = app.router.options.routes.filter(v => v.name === "jishuinUserU1")[0]
+      let jishuinUType = app.router.options.routes.filter(v => v.name === "jishuinUserUID1")[0]
       let jishuinU = {
         name: 'jishuinSeoU_$',
         path: '/u/:id',
@@ -92,16 +99,16 @@ export default ({ app, context, req, store }) => {
         app.router.options.routes.unshift(jishuinUT)
         app.router.options.routes.unshift(jishuinC)
         app.router.options.routes.unshift(jishuinCT)
-        app.router.matcher.addRoutes([ jishuinU, jishuinUT, jishuinC, jishuinCT ])
-      } catch ( e ) {
+        app.router.matcher.addRoutes([jishuinU, jishuinUT, jishuinC, jishuinCT])
+      } catch (e) {
         console.log(e)
       }
     }
-    
+
     if (isJob) {
       window.__NUXT__.routePath = app.context.route.path.replace(/^\/job/, '')
-      let jobIndex = app.router.options.routes.filter(v => v.name === 'JobListSeoIndex')[ 0 ]
-      let jobDetail = app.router.options.routes.filter(v => v.name === 'job-detail-id')[ 0 ]
+      let jobIndex = app.router.options.routes.filter(v => v.name === 'JobListSeoIndex')[0]
+      let jobDetail = app.router.options.routes.filter(v => v.name === 'job-detail-id')[0]
       let jobIndexNow = {
         name: 'job_$',
         path: '/*',
@@ -115,27 +122,27 @@ export default ({ app, context, req, store }) => {
       try {
         app.router.options.routes.unshift(jobIndexNow)
         app.router.options.routes.unshift(jobDetailNow)
-        app.router.matcher.addRoutes([ jobIndexNow, jobDetailNow ])
-      } catch ( e ) {
+        app.router.matcher.addRoutes([jobIndexNow, jobDetailNow])
+      } catch (e) {
         console.log(e)
       }
     }
-    
+
     console.log('router', app.router)
-    
+
     // app.router.beforeEach((to, from, next) => {
     //   console.log("location.href", to, from)
     //   next()
     // })
-    
+
   }
 }
 
 function getMatchedComponents(route, matches = false, prop = 'components') {
   return Array.prototype.concat.apply([], route.matched.map((m, index) => {
-    return Object.keys(m[ prop ]).map((key) => {
+    return Object.keys(m[prop]).map((key) => {
       matches && matches.push(index)
-      return m[ prop ][ key ]
+      return m[prop][key]
     })
   }))
 }

+ 1 - 1
plugins/seoRouter.js

@@ -59,7 +59,7 @@ const extendRoutes = (routes, resolve) => {
    * 404
    */
   routes.push({
-    name: 'JobListSeoIndex',
+    name: '404',
     path: '*',
     component: resolve(__dirname, '../pages/404.vue')
   })