I'm developing an application where my user needs to login, in this sense logging in is slightly different as the user isn't registered per say. They enter their name, and room name then they connect. The room itself contains all of the settings required for the users such as;
So what I'm looking to do is hook on to the route event, so I can force the user to go to the /login
root if they're not logged in.
Surely there must be a DRY way of doing this without adding a conditional to each route?
Backbone's Router has an execute
method that you can override. It is called every time a route is matched, before the callback is called:
var Router = Backbone.Router.extend({
execute: function(callback, args) {
// Do what you want here!
if (callback) callback.apply(this, args);
}
});
The method was added with the 1.1.1 release on Feb. 13, 2014.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With