I am working on a backbone.js-application and have reached the point where I have a number of routers and views representing each part of my application. In the simplified r
I have a really simple implementation, I'm just starting my application now and don't know how this is going to hold up in the long run, but it looks something like this:
Edit: Here's what the entire file would look like. this.render will be another function of myRouter.
var myRouter = Backbone.Router.extend({
routes: {
'path/to/account' : 'account',
'path/to/users': 'users'
}
account: function() {
view = new AccountView({});
this.render(view);
},
users: function() {
view = new UserView({});
this.render(view);
},
render: function (view) {
//Close the current view
if (this.currentView) {
this.currentView.remove();
}
//render the new view
view.render();
//Set the current view
this.currentView = view;
return this;
}
});