これが私のバックボーン ルーターです。
var Router = Backbone.Router.extend({
routes: {
"": "home",
"home": "home",
"about": "about",
"works": "works",
"work/:id" : "work",
"news": "news",
"contact": "contact"
},
initRoutes: function(e) {
this.on('route:home', function() {
page.activepage = "home";
page.render();
});
this.on('route:about', function() {
page.activepage = "about";
page.render();
});
this.on('route:works', function() {
page.activepage = "works";
page.render();
});
this.on('route:work', function(id) {
page.activepage = "works";
page.param = id;
page.render();
});
this.on('route:news', function() {
page.activepage = "news";
page.render();
});
this.on('route:contact', function() {
page.activepage = "contact";
page.render();
});
},
initialize: function(){
var self = this;
Backbone.history = Backbone.history || new Backbone.History({});
root = "kitchenV3/"+lang;
var enablePushState = true;
var pushState = !! (enablePushState && window.history && window.history.pushState);
Backbone.history.start({
pushState: pushState,
root: root
});
self.initRoutes();
}
});
ご覧のとおり、すべてのルートは基本的に同じことを行っています (ルート名とパラメーターに応じてコンテンツをレンダリングします)。では、再帰を避けるために ,,this.on(route:about)..." を書き換えるにはどうすればよいでしょうか?