2

我有一个使用AppRouterEventAggregator配置的 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'
  },
});
4

1 回答 1

1

哇!多么愚蠢的错误——至少我在识别这些方面变得越来越快。

在 AppRouter 中声明路由与在 Backbone 路由器中不同。

木偶:appRoutes

常规骨干网:路由

于 2012-12-16T05:27:41.760 回答