1

I have a backbone.js site. when you click on a link a page slides in - when you press the back button i'd like it to slide out rather than the previous page sliding in over it.

Is there a way to detect if it was a back button being pressed or a way to run a different function off of a back button press?

Dustin Silk
  • 4,320
  • 5
  • 32
  • 48

1 Answers1

0

You have to enable Backbone's History with:

Backbone.history.start({ pushState: true })

If your browser support push state, you will be able to receive events regarding url change, for example when the back button is pressed, and your router will do the rest (rendering the correct view for the current url). This means that if you go to your app at the url /app and then navigate your single page app with Router.navigate and go to /app/account, Backbone will put an entry in the browser's history. When the back button is pressed, you will be brought back to /app without a page reload, but your Router will be notified of this url change nonetheless, and will react accordingly (ie, render the correct view).

namero999
  • 2,882
  • 18
  • 24