backbone.js中的高级路由,具有功能分组

时间:2012-06-05 14:53:01

标签: javascript backbone.js routes

以下是我的路线结构示例:

routes:{
 "*actions" : "defaultHandler", //some default handler
 //handlers for all pages
 "Page1" : "Page1",
 . . . . . . . . . .
 "PageN" : "PageN",

 //and now I have a module, with it's own pages, and routes for it has similar look:
 "Module/Page01" : "Page01",
 . . . . . . . . . .
 "Module/PageNN" : "PageNN",

 /* and now I have to do some task for all navigations 
    to the Module and I am trying to make this: */

 "Module/*path" : "moduleHandler"

  /* and it's not working, because in this case on navigate, for example
     to the page "Module/Page01" only moduleHandler responding, not Page01 handler */
}
像那样。我需要两个处理程序来回应。在文档

中找不到任何技巧

1 个答案:

答案 0 :(得分:1)

你需要这样的东西:https://github.com/FLOChip/backbone_router_filter 但是,当然,这只是一个例子,你应该实现依赖于路由的过滤。如果您遇到困难,请随时询问。

已更新:我刚发现:https://github.com/angelo0000/backbone_filters。如果我明白这正是你想要的。

var R = Backbone.Router.extend({
    routes: {
        "page1": "page1",
        "pageN": "pageN",
        "module/page01": "page01",
        "module/pageNN": "pageNN",
        "*actions" : "defaultHandler"
    },

    before: {
        '^module/': 'moduleFilter'
    }
    //...
 });