バックボーンルーターのドキュメントに記載されているルート方法を使用してみましたが、ルーターの「routes」オブジェクトを調べても、追加されたルートが表示されません。
ルーターのroutesオブジェクトは、extends関数に渡したハッシュです。
実際のルートはBackbone.historyオブジェクトに追加されます。
したがって、Router.route()関数を使用すると、ルーターのルートハッシュは変更されませんが、実際にはルートがBackbone.historyに追加され、期待どおりに機能します。
Workspace = Backbone.Router.extend({
routes: {
"help": "help", // #help
"search/:query": "search", // #search/kiwis
"search/:query/p:page": "search" // #search/kiwis/p7
},
help: function() {
console.log("help");
},
search: function(query, page) {
console.log("search",query,page);
},
new: function() {
console.log("new");
}
});
Main = Backbone.View.extend({
tagName: 'div',
initialize: function() {
app.route('new','new');
},
render: function() {
return this;
}
});
app = new Workspace();
Backbone.history.start();
main = new Main();
app.navigate('new',{trigger:true}); //=> "new"
実例:http://jsfiddle.net/edwardmsmith/XsDQu/4/