2
我有一個使用AppRouter以及EventAggregator配置的Backbone.Marionette應用程序。Backbone.Marionette控制器不工作
初始化程序啓動路由器,然後啓動歷史記錄。我確定我的EventAggregator設置正確 - MyVent.trigger('abc')在控制檯中正常工作。正如預期的那樣,導航到未定義的URL會導致404錯誤,AppRouter似乎也能正常工作。
我錯過了什麼嗎?
//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'
},
});
談過德里克·貝利,木偶的創造者,這個昨晚。他證實了我的懷疑。 – snakesNbronies
如果我有一條叫做'家'的路線,我也發現了同樣的問題。如果我將它重命名爲'index',那麼它就會開始工作。 – simbolo