API Docs for: 1.0.0
Show:

Rebar.DependencyRouter Class

Extends Backbone.Router

Handles all pre and post routing functionality. This is the default router when you initialize an Application instance. Once initialized any time the browser's anchor location changes this class notifies the rest of the application of the new directory, file, view and anchor to use. To use simply listen to the application's routeDidChange or the router's routeDidChange event firing and then implement the AMD loader that makes the most sense (for your project) to use.

Constructor

Rebar.DependencyRouter

()

Example:

// requirejs example
router.on("routeDidChange", function(route){
    var mReq = require([resource], function(a) {
        var Constructor = a[view];
        var v = new Constructor({
            routeData: data
        });
        delegate.addSubView(v);
    }, function(e) {
        console.log("Error: " + e);
    });
});

Methods

getFileLocation

(
  • route
)
private

Takes a passed route object and determines a file location

Parameters:

  • route Object

    Object formed in parseRoute method

handleAll

() private

Handles every route that doesn't match any of the previous matches

handleNoHash

() private

Reroute the page to the page referenced as landing

parseRoute

(
  • route
)
private

Parses a passed route string and determines directory, file, view and data

Parameters:

  • route String

    The current Backbone.history fragment

parseRouteData

(
  • query
)
private

Parse the query string provides and returns key value pair object

Parameters:

  • query String

setStaticRoute

(
  • name
  • method
)

Adds the name and method to the staticRoutes object as a key/value pair

Parameters:

  • name String
  • method Function

setStaticRoutes

(
  • routes
)

Takes key value pairs from an object and sets them to the staticRoutes object on the router

Parameters:

  • routes Object

Properties

landing

String

Default landing for no hash. Where the browser will be routed to when landing on the root url of the application.

Default: ""

routes

Object route key value pairs private

Define only the route hash here because we'll be using dependency routing for the rest of the functionality.

Default: { "": "handleNoHash", "*splat": "handleAll" }

staticRoutes

Object static route key value pairs private

This object is empty by default, but routes added here, either manually, or through the two methods, setStaticRoute and setStaticRoutes, will bypass the handleAll and handleNoHash methods referenced in the routes object.