第五天——范式路由之泛式路由分析
要想把泛式路由的特性,加入到系统中,第一个想到的是修改App.js文件的两个方法
泛式路由分析
要想把泛式路由的特性,加入到系统中,第一个想到的是修改App.js
文件的两个方法:
App.prototype.get = function(route,handle){ this._route_get_handles[route] = handle; } App.prototype.post = function(route,handle){ this._route_post_handles[route] = handle; }
上周末加入了简单的路由功能,对GET/POST进行了分离处理,也就是说 app.get("/abc") 和 app.post("/abc") 是不同的,stuwebfk框架会根据get或post方法智能判断路由到的处理器。那么,即使是泛式,也必然会分两个仓库对象,保存路由和其处理函数。还是使用原有的 this._route_get_handles
和 this._route_post_handles
不过,以前是map格式,现在要修改成数组对象。
修改后的代码是:
App.prototype.get = function(route,handle){ this._route_get_handles.push({route:route,handle:handle}) } App.prototype.post = function(route,handle){ this._route_post_handles.push({route:route,handle:handle}) }
当有客户请求时,会判断是GET还是POST方法,然后循环this._route_get_handles或this._route_post_handles的数组,找到匹配的路由,然后调用该路由的处理器handle即可,找不到就发送 404 。
分析就到这里,下节实际编码,并实现泛式路由功能。
很赞哦! ( 0
)
相关文章
- 利用 html2canvas 生成文章缩略图
- 纪录片《穹顶之下》全集103分钟1080P高清完整视频
- DoraCMS v2.1.5 版本更新
- DoraCMS v2.1.2 Docker 版本(生产环境)
- Nodejs 内容管理系统 DoraCMS 2.1.4 发布
- DoraCMS 插件化探索(一)
- DoraCMS 2.1.4 关于 '指定用户' 功能的优化说明
- DoraCMS 2.1.4 (发布版非源码) 抢先体验
- angularjs filter 详解
- angularJs的html转义过滤器
- ng-switch on、ng-if/ng-show/ng-hide/ng-disabled标签
- angularjs分页教程