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
As with pretty much any Backbone question, there are lots of ways to handle this. The way I approached it in my current project was to put everything in a global custom namespace, and use that to pass around the necessary references:
var MyNamespace = {};
MyNamespace.init = function() {
MyNamespace.appView = new MyAppView();
MyNamespace.router = new MyRouter();
// etc
}
Views could then refer to MyNamespace.router as necessary. But it looks like this won't work/isn't encouraged with require.js, so here are some other options:
Don't ever call the router explicitly - instead, change a global state object that the router listens to. This is actually how I've done things in my current project - see this response for more details.
Attach the router to your top-level view, often called AppView, make that globally accessible, and use AppView.router.navigate().
Make another module that provides a navigate utility function that calls Backbone.history.navigate() internally. This isn't much different from what you're doing, but it would make it slightly more modular and keep you from using the global reference all the time. This also allows you to change the internal implementation.