Skip to content

Instantly share code, notes, and snippets.

@rjz
Created August 17, 2012 02:33
Show Gist options
  • Select an option

  • Save rjz/3375413 to your computer and use it in GitHub Desktop.

Select an option

Save rjz/3375413 to your computer and use it in GitHub Desktop.
Monkey-patch Backbone.History to add route filtering
# Monkey-patch Backbone.History to filter/rewrite/inject routes
# see: http://blog.rjzaworski.com/2012/08/filtering-backbone-routes/
do (History = Backbone.History) ->
_navigate = History::navigate
methods =
filter: (fragment) ->
if fragment == 'NOOP'
return null
fragment
navigate: (fragment, options) ->
fragment = @filter(fragment)
if filter?
_navigate.call @, fragment, options
_.extend History::, methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment