【发布时间】:2012-03-24 14:37:16
【问题描述】:
这是我的 application-router.js 文件,我正在其中创建 Backbone.Router 对象,其中只有几条路线:
var App = App || {};
App.Router = Backbone.Router.extend({
routes : {
'' : 'showDashboard', // Not shown
'*other': 'showModalError'
},
defaultRoute : function(other) { $('#modal404').modal(); }
});
在主 javascript 文件 application.js 中,我想以编程方式添加路由。我试过route() 函数,但它不起作用,没有添加路由。但是,它可以将对象传递给“构造函数”,但这将覆盖已定义的路由:
// This works and overrides all defined routes in App.Router
var router = new App.Router({ routes : { '/test/me' : 'testRoute' } });
// This is not working
router.route(ExposeTranslation.get('customers.new.route'), 'newCustomer');
router.route('/test/me/again', 'testAgainRoute');
其实console.log(App.Router)表示:
routes Object { /test/me="testRoute"}
我想我错过了一些我无法弄清楚的东西,我开始学习这个强大的 JavaScript 小片段。
【问题讨论】:
标签: backbone.js routing backbone-routing