1

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.

Hetfield Joe
  • 1,443
  • 5
  • 15
  • 26

1 Answers1

0

Seems to me like the best option is to have a seperate page for your login. And although that may sound like a copout answer, I think a login page should be a gateway into your application, not really part of the application itself.

jcvandan
  • 14,124
  • 18
  • 66
  • 103
  • Thanks for advice dormisher. Indeer, I'm thinking about the same thing. but I still want to know why that unexpected thing happend. and I want make a "smooth" login effect, without page jumping. – Hetfield Joe Apr 24 '13 at 01:00