eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.91k stars 1.82k forks source link

csr(renderClient方法)和ssr(render方法)渲染模式混用报错 #4547

Closed xiaoyanzheng closed 3 years ago

xiaoyanzheng commented 3 years ago

What happens?

复现步骤 1、使用easywebpack cli,初始化一个项目 1)全局安装easywebpack 2)easywebpack init,初始化一个项目,如下图 image

3)修改admin.ts的代码,ctx.ssr的状态可以由接口动态的控制,自行实现(比如使用自定义的cookie) image

2、启动服务 npm run dev

3)访问http://local.test.com:7001/ 走的是renderClient方法(因为ctx.ssr默认是undefined)

4)访问http://local.test.com:7001/admin

5)再次访问http://local.test.com:7001/ 报错 image 2020-12-15 13:49:19,015 ERROR 54504 [-/127.0.0.1/-/23ms GET /] nodejs.TypeError: Cannot read property 'matched' of undefined at render (/Users/haha/work/test/demo1/node_modules/vue-router/dist/vue-router.common.js:356:25) at createFunctionalComponent (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3052:30) at createComponent (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3225:12) at _createElement (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3415:15) at createElement (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3347:10) at vm._c (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3484:42) at Proxy.render (webpack:///./app/web/component/layout/admin/content/index.vue?./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options:12:8) at Vue._render (/Users/haha/work/test/demo1/node_modules/vue/dist/vue.runtime.common.dev.js:3538:22) at resolve (/Users/haha/work/test/demo1/node_modules/vue-server-renderer/build.dev.js:8656:28) at waitForServerPrefetch (/Users/haha/work/test/demo1/node_modules/vue-server-renderer/build.dev.js:8287:3) at render (/Users/haha/work/test/demo1/node_modules/vue-server-renderer/build.dev.js:8658:5) at Object.renderToString (/Users/haha/work/test/demo1/node_modules/vue-server-renderer/build.dev.js:9183:9) at /Users/haha/work/test/demo1/node_modules/egg-view-vue-ssr/lib/engine.js:137:21 at new Promise () at Engine.renderString (/Users/haha/work/test/demo1/node_modules/egg-view-vue-ssr/lib/engine.js:136:12) at Engine.renderClient (/Users/haha/work/test/demo1/node_modules/egg-view-vue-ssr/lib/engine.js:155:17)

Context

i5ting commented 3 years ago

https://github.com/easy-team/easywebpack 里提issue更合适一些。

另外,如果你真的想做好egg + vue 的ssr,可以参考https://github.com/ykfe/egg-react-ssr,自己改一个vue版本的。

hubcarl commented 3 years ago

@xiaoyanzheng 这个我查一下