当前位置: 首页 > 工具软件 > Vue-SSR > 使用案例 >

路由ssr服务器信息不完整,vue-router addRoutes方法无法再 vue-ssr 的服务端动态添加路由...

濮阳振海
2023-12-01

vue服务端渲染中,动态添加路由,在客户端可以正常加载,在服务端失效,请问怎么解决?

ssr server-entry.js

export default context => {

return new Promise((resolve, reject) => {

const { app, router } = create()

router.push(context.url)

router.onReady(() => {

const matchedComponents = router.getMatchedComponents()

if (!matchedComponents.length) {

return reject({ code: 404 })

}

resolve(app)

}, reject)

})

}

the first client-entry

import Vue from 'vue'

import App from './App.vue'

import { createRouter } from './router'

global.create = () => {

const router = createRouter()

const app = new Vue({

router,

render: h => h(App)

})

router.onReady(() => {

app.$mount('#app')

})

return { app, router }

}

the second client-entry

const { app, router } = create()

create = () => {

router.addRoutes([

{ path: '/core/ppp', name: 'core', component: () => import('./Core.vue') }

])

return {app, router}

}

开启服务器后,core这个路由在客户端页面可以点开,一刷新服务端却服务渲染出来。。。

 类似资料: