In my routers, I’ve specified router ‘#’ to call the index function. This works the first time when the app loads. But after navigation away and then going back, the view no longer renders. Here’s my router:
CommunityApp.Routers.Main = Backbone.Router.extend({
routes: {
'': 'index',
'#': 'index',
},
initialize: function () {
this.communities = new CommunityApp.Collections.Communities();
this.communities.fetch();
},
index: function() {
console.log('index called');
view = new CommunityApp.Views.CommunitiesIndex({collection: this.communities});
$('#main').html(view.render().el);
}
});
I see that the function is called because it logs ‘index called’. However the view is only rendered the first time i navigation to localhost:3000/#. If I click somewhere else which leads back to ‘#’, the function gets called but CommunitiesIndex view never gets inserted in the DOM.
Thanks
I know this is an old thread, but I’ll add my 2 cents.
The corresponding route is
''.The route is just blank. The second part can be whatever you want, i.e.
'index','home','landing'.