If I understand your problem correctly, I don't believe you need a hash and I do believe you can implement the modal by simply adding more routes. If you need to support a login modal over other existing routes, simply add another route that adds login to the end. Here would be an example:
var Login = Backbone.Model.extend({
closeLogin: function () {
this.set({ open: false }, { silent: true });
this.trigger('loginClosed');
}
});
var LoginView = Backbone.View.extend({
el: '#loginModal',
initialize: function () {
this.listenTo(this.model, 'loginClosed', this.closeLogin);
},
closeLogin: function () {
// do whatever you would normally do to close the modal
}
});
var Router = Backbone.Router.extend({
routes: {
'/login': 'defaultRouteLogin',
'': 'defaultRoute',
'otherpage/login': 'otherPageRouteLogin',
'otherpage': 'otherPageRoute'
},
defaultRoute: function () {
// defaultRoute behaviors
this.login.closeLogin();
},
defaultRouteLogin: function () {
// defaultRoute behavior
// instantiate login modal
},
otherPageRoute: function () {
// otherPageRoute behavior
this.login.closeLogin();
},
otherPageRouteLogin: function () {
// otherPageRoute behavior
// instantiate login modal
},
initialize: function () {
this.login = new Login();
this.loginView = new LoginView({ model: this.login });
}
});
To support back-button behavior, use a method that closes your login modal on every route where you could open your modal. Be sure to order the routes correctly.