I am separating my views and router into separate files with require. I then have a main.js file that instantiates the router, and also renders my default view.
My r
In case anyone else is looking for a solution to this problem like I was, I'm posting what I ended up doing. If you're using the boilerplate backbone.js, then you will have an initialize()
function in router.js
. I modified my initialize()
function to look like the following:
initialize = function () {
var app_router;
app_router = new AppRouter();
// Extend the View class to include a navigation method goTo
Backbone.View.goTo = function (loc) {
app_router.navigate(loc, true);
};
Backbone.history.start();
};
Due to backbone.js's particular flavour of inheritance, this allows allows me to call MyView.goTo(location);
from within any of my views.