I just started to delve into backbone.js and I am not sure what is the best way to use routers.
App.Events = _.extend({}, Backbone.Events);
App.HouseDetailRouter = Backbone.Router.extend({
routes: {
'': 'main',
'details/:id': 'details',
},
initialize: function() {
},
main: function() {
App.Events.trigger('show_main_view');
},
details: function(id) {
model = App.houseCollection.get(id);
App.Events.trigger('show_house', model);
},
});
Should routers fire events like above, and then have views listen to these events?
This is actually not a bad way to use a router as it relegates the router to simply handling routes as opposed to business logic. What you might consider when using a router this way is to have a controller object listen to the router events then update the app’s models. When the models change state the views would update.