Skip to content

Instantly share code, notes, and snippets.

@ssafejava
Last active December 17, 2015 16:39
Show Gist options
  • Save ssafejava/5640593 to your computer and use it in GitHub Desktop.
Save ssafejava/5640593 to your computer and use it in GitHub Desktop.
Add 'routeNotFound' event to Backbone.History.
var oldLoadUrl = Backbone.History.prototype.loadUrl;
_.extend(Backbone.History.prototype, {
/**
* Override loadUrl & watch return value. Trigger event if no route was matched.
* @return {Boolean} True if a route was matched
*/
loadUrl : function() {
var matched = oldLoadUrl.apply(this, arguments);
if(!matched){
this.trigger('routeNotFound', arguments);
}
return matched;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment