| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- export default ({ app, context,req, store }) => {
-
- if (process.server) {
- let host = req.headers.host;
- const isKaifain = host.indexOf('kaifain') !== -1
- const isJishuin = host.indexOf('jishuin') !== -1
- const isJob = host.indexOf('job') !== -1
- return
- }
-
- if (process.client) {
- 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 kaifainIndexNow = {
- name: 'kaifain_$',
- path: '/*',
- component: kaifainIndex.component
- }
- let kaifainDetailNow = {
- name: 'kaifainSeoDetails_$',
- path: '/s/:tid',
- component: kaifainDetail.component
- }
- let kaifainCaseDetailNow = {
- name: 'kaifainCaseSeoDetails_$',
- path: '/d/:tid',
- component: kaifainCaseDetail.component
- }
- try {
- app.router.options.routes.unshift(kaifainIndexNow)
- app.router.options.routes.unshift(kaifainDetailNow)
- app.router.options.routes.unshift(kaifainCaseDetailNow)
- app.router.matcher.addRoutes([ kaifainIndexNow, kaifainDetailNow, kaifainCaseDetailNow ])
- } 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 jishuinU = {
- name: 'jishuinSeoU_$',
- path: '/u/:id',
- component: jishuinUIndex.component
- }
- let jishuinUT = {
- name: 'jishuinSeoUType_$',
- path: '/u/:id/:type',
- component: jishuinUType.component
- }
- let jishuinC = {
- name: 'jishuinSeoC_$',
- path: '/c/:id',
- component: jishuinCIndex.component
- }
- let jishuinCT = {
- name: 'jishuinSeoCT_$',
- path: '/c/:id/:type',
- component: jishuinCType.component
- }
- try {
- app.router.options.routes.unshift(jishuinU)
- 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 ) {
- 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 jobIndexNow = {
- name: 'job_$',
- path: '/*',
- component: jobIndex.component
- }
- let jobDetailNow = {
- name: 'jobSeoDetails_$',
- path: '/d/:tid',
- component: jobDetail.component
- }
- try {
- app.router.options.routes.unshift(jobIndexNow)
- app.router.options.routes.unshift(jobDetailNow)
- 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) => {
- matches && matches.push(index)
- return m[prop][key]
- })
- }))
- }
|