這是有效的。使用router時不會觸發頁面加載時的初始骨幹路由.route
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的正確功能嗎?
沒錯,就是工作。但爲什麼正則表達式不會在加載時觸發? – erickreutz
以及我的下一個建議是去除主要的正斜槓。你可以試試'/^admin $ /'作爲你的regEx表達式嗎? – timDunham