这是我当前的路由器:
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
以允许小节吗?
建议?
答案 0 :(得分:0)
重新排序路线并且有效:
CRM.Router = Marionette.AppRouter.extend({
appRoutes: {
"customers" : "listCustomers",
"customers/add" : "newCustomer",
"customers/:id" : "showCustomer",
"customer/search" : "showCustomerSearch"
}
});