Barf - Backbone Async Route Filter
Backbone Async Route Filter - Express style async route filters.
Installation
npm install barf
or if you're into bower
bower install --save barf
Usage
module.exports = Backbone.Router.extend({
routes: {
'users': 'usersList',
'users/:id': 'userShow'
},
before: {
'users(/:id)': 'checkAuth',
'*any': function (fragment, args, next) {
console.log('Attempting to load ' + fragment + ' with arguments: ', args);
next();
}
},
after: {
'*any': function (fragment, args, next) {
goog._trackPageview(fragment);
next();
}
},
checkAuth: function (fragment, args, next) {
$.ajax({
data: somedata,
success: function () {
next();
},
error: function () {
Backbone.history.navigate('', {
trigger: true
});
}
});
}
});
LICENSE
MIT