| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- export default ({
- app,
- context,
- req,
- store
- }) => {
- 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 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: '/*',
- component: kaifainIndex.component
- }
- let kaifainDetailNow = {
- name: 'kaifainSeoDetails_$',
- path: '/s/:tid',
- component: kaifainDetail.component
- }
- let kaifainCaseDetailNow = {
- name: 'kaifainCaseSeoDetails_$',
- path: '/d/:tid',
- component: kaifainCaseDetail.component
- }
- let kaifainAddNow = {
- name: 'kaifainAdd_$',
- path: '/add',
- component: kaifainAdd.component
- }
- let kaifainPreviewNow = {
- name: 'kaifainPreview_$',
- path: '/preview',
- component: kaifainPreview.component
- }
- let kaifainPreviewCaseNow = {
- name: 'kaifainPreviewCase_$',
- path: '/previewCase',
- component: kaifainPreviewCase.component
- }
- try {
- app.router.options.routes.unshift(
- kaifainPreviewCaseNow,
- kaifainPreviewNow,
- kaifainAddNow,
- kaifainCaseDetailNow,
- kaifainDetailNow,
- kaifainIndexNow)
- app.router.matcher.addRoutes([
- kaifainIndexNow, kaifainDetailNow, kaifainCaseDetailNow,
- kaifainAddNow, kaifainPreviewNow, kaifainPreviewCaseNow
- ])
- } 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 === "user-collect_article-id-type")[0]
- let jishuinCType = app.router.options.routes.filter(v => v.name === "user-collect_article-id-type")[0]
- let jishuinUIndex = app.router.options.routes.filter(v => v.name === "user-id-type")[0]
- let jishuinUType = app.router.options.routes.filter(v => v.name === "user-id-type")[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 === 'job')[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("beforeEach", 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]
- })
- }))
- }
|