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
for me i added an object to the main application like so;
define(['jquery','underscore','backbone','views/personView','views/peopleView','views/textView'],function($,_,backbone,PersonView,PeopleView,TitleView){
var Router = Backbone.Router.extend({
routes:{
'':'home',
'edit/:id':'editPerson',
'new':'editPerson',
'delete/:id':'deletePerson'
}
})
var initialize = function(){
var router = new Router();
window.app = {
router:router
}
router.on('route:home',function(){
})
//enable routing using '#'[hashtag] navigation
Backbone.history.start();
};
return {
initialize:initialize
};
});
and inside your view, you can say windows.app.router.navigate({'',trigger:true}) . Don't know if global scoping is good practice in this case, but it worked for me.