In Backbone.js, what is the equivalent of HttpResponseRedirect in Django?
In one Backbone.View, I need to submit data to the server, and then redirect the user to anoth
Here's the approach I've been taking:
Assuming you have a router defined with routes like these:
var MyRouter = Backbone.Router.extend({
routes: {
'first-route': 'first',
'second-route': 'second'
},
first: function() {
// render first view
},
second: function() {
// render second view
}
// ...
});
I usually just use tags and set the href attribute to the hash I want to redirect to:
First
Alternatively, if you want to "redirect" from within your JavaScript, you could set the location hash explicitly:
window.location.hash = 'first';
I'm not 100% sure that the latter is 'best practice', but I've seen it done in a number of good tutorials.
// Edit
So after re-reading your original question, you could 'redirect' after sync calls back from the server simply by setting the location hash.