snakesNbronies
snakesNbronies

Reputation: 3920

Backbone.Marionette controller not working

I have a Backbone.Marionette app configured using the AppRouter as well as the EventAggregator.

The initializer starts the router, and then history. I know for sure that my EventAggregator is set up properly - MyVent.trigger('abc') works properly in the console. The AppRouter also seems to be working properly as navigating to an undefined URL results in a 404, as expected.

Am I missing something?

//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'
  },
});

Upvotes: 2

Views: 1202

Answers (1)

snakesNbronies
snakesNbronies

Reputation: 3920

WOW! What a stupid mistake - at least I'm getting faster at identifying these.

Declaring routes in AppRouter, is different than in the Backbone router.

Marionette: appRoutes

Regular Backbone: routes

Upvotes: 1

Related Questions