这是我的
在主JavaScript文件
实际上,
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"}
我觉得我缺少某些东西,但我无法弄清楚。我开始学习这个强大的js小工具。