Skip to content

Step 7 - Use AppRouter

Compare
Choose a tag to compare
@dmytroyarmak dmytroyarmak released this 05 Feb 11:20
· 2 commits to gh-pages since this release
  1. In router.js change Backbone.Router.extend to Marionette.AppRouter.extend

  2. Remove all routes except home

    ContactManager.Router = Backbone.Router.extend({
      routes: {
        '': 'home'
      }
    });
    
  3. Move home method from ContactManager.Controller to ContactManager.Router

    home: function() {
      this.navigate('contacts', {
        trigger: true,
        replace: true
      });
    }
    
  4. Bind contacts routes to router in application initialization

    ContactManager.addInitializer(function(data) {
      var contacts = new ContactManager.Collections.Contacts(data.contacts),
          router = new ContactManager.Router(),
          controller = new ContactManager.Controller({
            contacts: contacts,
            router: router,
            mainRegion: this.mainRegion
          });
    
      router.processAppRoutes(controller, {
        'contacts': 'showContacts',
        'contacts/new': 'newContact',
        'contacts/edit/:id': 'editContact'
      });
    });
    

Difference