什么是允许"子目录的正确方法"在Backbone Marionette路由器?

时间:2013-10-17 20:19:34

标签: backbone.js marionette backbone-routing

这是我当前的路由器:

CRM.Router = Marionette.AppRouter.extend({
    appRoutes: {
        "customers"         : "listCustomers",
        "customers/:id"     : "showCustomer",
        "customers/add"     : "newCustomer",
        "customer/search"   : "showCustomerSearch"
    }
});
CRM.navigate = function (route, options) {
    options || (options = {});
    Backbone.history.navigate(route, options);
}
CRM.getCurrentRoute = function () {
    return Backbone.history.fragment;
}
CRM.addInitializer(function () {
    var router = new CRMApp.Router({
        controller: API
    });
});
CRM.on("initialize:after", function () {
    if (Backbone.history) {
        Backbone.history.start({ pushState: true, root: '/app/' });
        if (this.getCurrentRoute() === "") {
            CRM.trigger("customers:list");
        }
    }
});

转到customers效果非常好,但转到customers/add似乎想要加载customers内容。不知道为什么。我应该采用不同的方式处理customers以允许小节吗?

建议?

1 个答案:

答案 0 :(得分:0)

重新排序路线并且有效:

CRM.Router = Marionette.AppRouter.extend({
    appRoutes: {
        "customers"         : "listCustomers",
        "customers/add"     : "newCustomer",
        "customers/:id"     : "showCustomer",
        "customer/search"   : "showCustomerSearch"
    }
});