Skip to content

Instantly share code, notes, and snippets.

@chrisekelley
Last active January 14, 2016 14:12
Show Gist options
  • Select an option

  • Save chrisekelley/915063b0d97fdcba8859 to your computer and use it in GitHub Desktop.

Select an option

Save chrisekelley/915063b0d97fdcba8859 to your computer and use it in GitHub Desktop.

Some notes on resolving Back button issue in backbone.js

This is mildly useful because it displays the transitions from current route to the next route. It is disappointing that not only hitting the back button triggers popState.

  window.addEventListener('popstate', (e) ->
    sendTo = Backbone.history.getFragment()
  #      console.log("sendTo: " + sendTo)
    console.debug('popstate', Backbone.history.fragment, '>', Backbone.history.getFragment());
    #      sendTo = "assessments"
    Tangerine.router.navigate(sendTo, { trigger: true, replace: true })
  )

We might be able to monitor when a route is fired and act upon it. In my testing, the following code, which logs the fragment and the upcoming fragment, is not very useful because by the time the code reaches this trigger, they are one and the same.

Backbone.history.on('route',  () ->
  console.debug('route fired: ', Backbone.history.fragment, '>', Backbone.history.getFragment());

);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment