Step 7 - Use AppRouter
-
In
router.js
changeBackbone.Router.extend
toMarionette.AppRouter.extend
-
Remove all routes except
home
ContactManager.Router = Backbone.Router.extend({ routes: { '': 'home' } });
-
Move
home
method fromContactManager.Controller
toContactManager.Router
home: function() { this.navigate('contacts', { trigger: true, replace: true }); }
-
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' }); });