It's just interesting if there is an easy way to run a custom function every time the Backbone.js router is used, without having to add it to each of the functions of the router. Now my script looks like this:
var AppRouter = Backbone.Router.extend({ routes: { '' : 'index', 'test': 'test', }, initialize: function() { }, index: function() { customFunction(); indexView.render(); }, test: function() { customFunction(); testView.render(); }, });
I would like to have something like this:
var AppRouter = Backbone.Router.extend({ routes: { '' : 'index', 'test': 'test', }, initialize: function() { }, index: function() { indexView.render(); }, test: function() { testView.render(); }, change: function() { customFunction(); } });
Does anyone have any suggestions?
hampusohlsson
source share