## 问题记录 1:routing-controllers 的坑 1 Bug: 使用注解 @Render 渲染模板后,第二次访问其他页面但是展示效果还是上次的页面,页面不进行渲染 原因: 1:action.renderedTemplate 被放入js闭包中, 一旦中间件初始化,视图将永远不会改变。 2:根本原因在于框架的开发者团队对koa2不熟悉。 路径:node_modules/_routing-controllers@0.7.7@routing-controllers/driver/koa/KoaDriver.js 行数:249行 解决: 增加代码使用 options.response.render,强制渲染模板 return options.response.render(action.renderedTemplate, renderOptions_1); 注意: 插件开发者已经解决该问题,但开发者未合并修改到主分支 所以 `yarn add routing-controllers` 下载下来的还是有Bug的代码,需要自己手动修改插件源码 Github 问题反馈地址:https://github.com/typestack/routing-controllers/pull/434 Github 修复分支记录:https://github.com/typestack/routing-controllers/pull/434/files/001b45a416e3f1dbde33e7e91fadb09111d4061d 2:routing-controllers 的坑 2 虽然按照上面方法暂时解决了问题,但是当我在前端页面和api数据之间进行来回访问,api接口界面会从正常变为前端模板页面,问题依旧存在!!! 作者没有时间继续维护项目,其他开发者解决了这个,github commit 提交记录的地址: https://github.com/typestack/routing-controllers/pull/434/commits/001b45a416e3f1dbde33e7e91fadb09111d4061d 解决:删除框架中 249行渲染代码,只保留 [坑1] 中添加的代码即可。 建议:下载 routing-controllers 的 typescript 源码,修改源码编译后上传到自己的npm市场 防止每次解决依赖后都需要重新修改框架源码,编译有难度和坑..mmp.....