Execute a function before changing route in Backbone.js

backbone.jsjavascript-framework

How can I get notified before a Backbone router call the specific routing function?

I'd like to have a generic "reset" function before rendering every page.

Is there any event I can bind?

Update: the solutions I found are based on extending the router or the history in order to trigger the event.

Best Answer

It looks like the 1.1.x release of Backbone has what you want with the Router.execute method:

MyRouter = Backbone.Router.extend({
  routes: {},

  // fired before every route. 
  execute: function(callback, args) {
    // ...
  }
});
Related Topic