1
votes

I have an app which consist of several modules, eg: contacts, meetings, reminders.

The urls are probably

1. /#contacts       ->    contacts module, listing page
2. /#contacts/45    ->    contacts module, detail page of contact id 45

3. /#meeting        ->    meetings module, listing page
4. /#meeting/67     ->    meetings module, detail page of meeting id 67

I use Marionette App.module('ContactMgr') , App.module('MeetingMgr') to separate modules.

Question: Which is the best practice?


A) separating routers in each module

 // in file js/app/ContactMgr/Router.js
 App.ContactMgr.Router = Marionette.AppRouter.extend({
    appRoutes: {
     'contacts':     'listContacts',
     'contacts/:id': 'showContact'
    }
 });

 //////////////////////////////////////////////

 // in file js/app/MeetingMgr/Router.js
 App.MeetingMgr.Router = Marionette.AppRouter.extend({
    appRoutes: {
     'meetings':     'listMeetings',
     'meetings/:id': 'showMeeting'
    }
 });

B) one router in app

 // in file js/app/app.js
 App.Router = Marionette.AppRouter.extend({
    appRoutes: {
     'contacts':     'listContacts',
     'contacts/:id': 'showContact',
     'meetings':     'listMeetings',
     'meetings/:id': 'showMeeting'
    }
 });
1

1 Answers

0
votes

As for me, multiple routers solution is better because each router makes sense only for it's module. Each router should use it's own controller and controller should use views/collections/models from it's module.

Actually the major idea of module is that you can add or remove them with minor changes in other parts of your application. So in case you use multiple routers solution if you want to add/remove module in your app you'll just need to add/remove it's instantiation in your app and routers controllers will be in your module.

But if you use single router solution you'll also have to edit you router, controller, etc.

So multiple routers approach is more modular.