Skip to content

nnance/backbone-unloader

Repository files navigation

backbone-unloader

npm version Build Status Dependency Status

Dynamically load and unload Backbone routes. Which provides the ability to:

  • Limit access to routes based on user rights
  • Can be triggered based on events like signoff/signon

Getting Started

Install with bower. If you haven't used bower before, be sure to check out the Getting Started guide, as it explains how to install Bower and install bower packages. Once you're familiar with that process, you may install this plugin with this command:

bower install backbone.unloader --save

Documentation

Backbone.Unloader extends the Backbone.Router to provide away to dynamically load an unload routes. It can be included in an application in the following ways:

AMD or CommonJS

var Backbone = require('backbone');
var unloader = require('unloader');

var router = new Backbone.Router();

Global

var router = new Backbone.Router();

Loading Routes

Routes can be loaded dynamically based on an event or a condition.

var router = Backbone.Router.extend({
  initialize: function(session){
    session.on('login', function(){
      this.loadRoutes({
        'home': 'showHome',
        'user/:id': 'showUser'
      });

    }.bind(this));
  }
});

Unloading Routes

Routes can be unloaded dynamically

var router = Backbone.Router.extend({
  initialize: function(session){
    session.on('logoff', function(){

      this.unloadRoutes();

    }.bind(this));
  }
});

About

Dynamically load and unload Backbone routes.

Resources

License

Stars

Watchers

Forks

Packages

No packages published