I'm trying to extend Backbone.History.loadUrl() to catch 404 errors:
var History = Backbone.History.extend({
loadUrl: function() {
var match = Backbone.History.prototype.loadUrl.apply(this, arguments);
if (!match) {
console.log('route not found');
}
return match;
}
});
(Backbone.history = new History).start();
This is based on the solution suggested here: https://github.com/jashkenas/backbone/issues/308#issuecomment-9482299.
The problem I'm encountering is that when I call (Backbone.history = new History).start()
on a valid route, it returns false. However, when I call Backbone.history.start()
on the same route, it returns true.
When I add a debugger to the extended loadUrl method, match
is set to false.
Any ideas about what's causing the discrepancy?