Answer the question
In order to leave comments, you need to log in
Why does Backbone.js still reload the page when clicking on links?
For example, there is a router with 2 pages. We do it like this:
app.Workspace = Backbone.Router.extend({
routes: {
'': function() {
new app.ShuffleView();
},
'shuffle': function() {
console.log('i\'am shitcoder!');
}
}
});
app.router = new app.Workspace();
Backbone.history.start({
pushState: true
});
app.router.navigate('/shuffle')
Answer the question
In order to leave comments, you need to log in
Already answered on stackoverflow: stackoverflow.com/questions/9328513/backbone-js-an...
initializeRouter: function () {
Backbone.history.start({ pushState: true });
$(document).on('click', 'a:not([data-bypass])', function (evt) {
var href = $(this).attr('href');
var protocol = this.protocol + '//';
if (href.slice(protocol.length) !== protocol) {
evt.preventDefault();
app.router.navigate(href, true);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question