我使用AppRouter以及EventAggregator配置了Backbone.Marionette应用。
初始化程序启动路由器,然后启动历史记录。我确信我的EventAggregator设置正确 - MyVent.trigger('abc')在控制台中正常工作。 AppRouter似乎也正常工作,因为导航到未定义的URL会产生404,如预期的那样。
我错过了什么吗?
//Initializer
MyApp.addInitializer(function(options){
//do stuff here
router = new MyRouter(MyController);
console.log('routing started!');
MyVent.trigger('routing:started'); <-- this works
});
//EventAggregator
MyVent = new Backbone.Marionette.EventAggregator();
MyVent.on('contactUs', function(){
console.log('ContactUs received by MyVent!');
startContactUsModal();
Backbone.history.navigate("contactus/");
});
MyVent.on('bookNow', function(){
console.log('BookNow received by MyVent!');
startBookNowModal();
Backbone.history.navigate("booknow/");
});
MyVent.on('home', function(){
console.log('home received by MyVent!');
startHome();
console.log('after starthome on myvent');
});
MyVent.on('routing:started', function(){
console.log('routing:started recieved at MyVent!');
if( ! Backbone.History.started) Backbone.history.start();
console.log('Backbone.history sucessfully started!');
});
//Controller
MyController = {
homeMethods:function(){
console.log('home receieved at mycontroller');
MyVent.trigger('home')
},
booknowMethods:function(){
MyVent.trigger('bookNow')
},
contactusMethods:function(){
MyVent.trigger('contactUs')
}
};
//Router
MyRouter = Backbone.Marionette.AppRouter.extend({
controller: MyController,
routes: {
'' : 'homeMethods',
'tours' : 'toursMethods',
'booknow' : 'booknowMethods',
'contactus' : 'contactusMethods'
},
});
答案 0 :(得分:1)
哇!这是多么愚蠢的错误 - 至少我在识别这些错误方面变得越来越快。
在AppRouter中声明路由,与Backbone路由器中的路由不同。
木偶: appRoutes
常规骨干:路线