I got a question about backbone router, pls help:
I have a router:
define(['views/index', 'views/login'], function(indexView, loginView) {
var SelinkRouter = Backbone.Router.extend({
currentView: null,
routes: {
'home': 'home',
'login': 'login'
},
changeView: function(view) {
if(null != this.currentView)
this.currentView.undelegateEvents();
this.currentView = view;
this.currentView.render();
},
home: function() {
this.changeView(indexView);
},
login: function() {
this.changeView(loginView);
}
});
return new SelinkRouter();
});
when the users arrived my site for first time, the "login" route was triggered, and take them to login page, after login, user was navigate to the "home" route by: window.location.hash = "home". now the user saw home page the url looks like : mysite.com/#home, this was fine.
problem is, at this point if I hit F5 key or refresh the page by someother way, althought the "home" route was triggered again (which is fine), at the same time the whole page was reloaded and all my js were reloaded again. so the application restart, it take me back to login page (too bad).
Is there anyone had same problem? should I stop page refresh? how?
many thanks for any idea.