Skip to content

Instantly share code, notes, and snippets.

@flintinatux
Created October 29, 2014 19:55
Show Gist options
  • Save flintinatux/ee911130d22cc161e217 to your computer and use it in GitHub Desktop.
Save flintinatux/ee911130d22cc161e217 to your computer and use it in GitHub Desktop.
module.exports = class SwappingRouter extends Backbone.Router
execute: (callback, args) ->
@params = @_parseParams args.pop()
callback?.apply this, args
navigate: (fragment, options={}) ->
url = new URI fragment.replace('#','')
url.query options.params if options.params?
super "##{url.toString()}", _.omit(options, 'params')
swap: (newView) ->
@currentView?.remove()
@currentView = newView
@$el.html @currentView.render().el
@currentView.swapped()
this
_parseParams: (params) ->
return {} unless params
new URI("?#{params}").query(true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment