这样做。
Admin.Routers.AppRouter = Backbone.Router.extend({
// home() gets trigger when I visit http://example.com/admin
routes: {
"admin": "home"
},
initialize: function() {},
home: function() {
log("Home");
}
});
这不起作用。
Admin.Routers.AppRouter = Backbone.Router.extend({
initialize: function() {
var that = this;
// home() DOES NOT get trigger when I visit http://example.com/admin
this.route(/^\/admin$/, "home", function() {
that.home();
});
},
home: function() {
log("Home");
}
});
这是router.route的正确功能吗?
答案 0 :(得分:0)
我假设您根据发布的示例网址使用{pushState: true}
。你能试试以下吗?
this.route("admin", "home", function() {
that.home();
});
答案 1 :(得分:0)
Backbone.history.start({ silent: false });