弄了个路由装饰器,类似于django url,支持扩展apps
发布于 12 年前 作者 ruandao 8020 次浏览 最后一次编辑是 8 年前

很简陋,不过应该是可以用了 地址: https://github.com/ruandao/Recursive

我把下面的移到 withSlash 分支去了,主的分支 不设置成强制 /了

思想: 该模块依赖于已有的app.get, app.post方法,仅是简单对其封装 建立一个类似于django urlpattern的可以扩展的route 分配器

以便能够建立可以复用的app

设计方案: 对于主 route 通过主动调用done函数来运行主设定的main函数, 而子route则通过dispatch 进行召唤 主route和子route 写法都如下,子route还可以嵌套下层route,当然在最下层的route是没有调用dispatch的

use manual 注意: 写路径的时候最前面的‘/’不用写 ,分配子route的时候如果分配的prefix没有以‘/’结尾,会自动在prefix上添加‘/’

##############################################################

routes.js

var routes = require(‘Recursive’).Routes;

routes.main = function(){

this.get(’’, func); # / this.get(‘News/’, func); # /News/ this.get(‘T/’, func); # /T/

this.post(‘News/’, func); # /News/ this.post(‘T/’, func); # /T/

this.dispatch(‘register’, require(’./apps/register/routes’);# /register/ this.dispatch(‘friends/’, require(’./apps/friends/routes’);# /friends/

} module.exports = routes;

下面是app.js中的调用方法 ##############################################################

app.js

… var routes = require(’./routes’); … routes.done(app); …

##############################################################

回到顶部