RouterBase
var BauplanRouterBase = require("bauplan.router.base");
or as part of the Bauplan bundle
var Bauplan = require("bauplan");
var BauplanRouterBase = Bauplan.BauplanRouterBase;
To create and instantiate a new Router instance
var Router = RouterBase.extend();
var router = new Router({
config: {
"foo/:param": "foo"
},
methods: {
"foo": function (param) {
…
}
}
});
This creates a route with a URL pattern
- foo - /^\/foo\/([^\/]+)$/ eg. /foo/lish
When called invokes the foo method with the argument param (lish)
The individual config properties can also be passed as objects
var router = new Router({
config: {
"bar" : {
name: "barbar",
authenticated: true
},
"baz/:a/:b/*c": {
name: "baz",
method: function (a, b, c) {}
}
},
methods: {
"barbar": function () {}
}
});
This creates 2 routes with the following URL patterns
- barbar - /^\/bar$/ ie. /bar
- baz - /^\/baz\/([^\/]+)\/([^\/]+)\/(.*)$/ eg. /baz/tas/tic/al/journey
The barbar route requires authentication and invokes the barbar method
The baz route invokes the method defined in the method property of config.baz, with the arguments a (tas), b (tic) and c (al/journey)
Link handling
All a element clicks are intercepted unless:
- _target
- .external
- mailto:
Returns
BauplanRouterBase
- Type
- constructor
Requires
- lodash
- jquery
- backbone
- bauplan.authentication
- bauplan.tracker
- Source:
Members
(private, static) previousStack
Registry for storing app’s previous state
- Source:
(static) reverseRoutes
Registry for reversed routes
- Source:
(private, static) urlStack
For storing app's URL previous and current history
- Source:
(private, inner) urlList :array
Simple array of URLs visited
Type:
- array
- Source:
Methods
(static) callRoute(route, optionsopt)
Navigate to a route by the name of the route, rather than by URL
Parameters
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
route |
string | Route name |
||
options |
object |
<optional> |
Options to pass to this.navigate |
|
options.trigger |
object |
<optional> |
true | Route triggering |
options.options |
object |
<optional> |
Overriding options |
|
options.params |
object |
<optional> |
Params to pass to route URL |
- Source:
(static) callRouteWithAuth(url, replaceopt)
Navigate to a route where the user can authenticate before proceeding to the desired URL
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL which requires authentication |
|
replace |
boolean |
<optional> |
Whether to replace the previous entry in the user agent’s history |
- Source:
(static) checkAuthenticatedUrl(url, replaceopt)
Checks whether a URL needs authentication
If it does, and the user is not authenticated, performs a redirect to an authentication page.
Once the user has authenticated, they will be redirected to the origally requested URL
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | URL to check |
|
replace |
boolean |
<optional> |
Whether to replace the previous entry in the user agent’s history |
- Source:
(static) getAuthRoute() → {string}
Get a redirect route based on whether the user has registered or not
- Source:
Returns
Authentication redirect route
- Type
- string
(static) getRoute(url) → {string}
Get the route that a URL resolves to
Parameters
Name | Type | Description |
---|---|---|
url |
string | URL to look up |
- Source:
Returns
Route name
- Type
- string
(static) getUrlList() → {array}
- Source:
Returns
List of app URLs in order visited
- Type
- array
(static) initialize(options)
Create router instance
- Register routes
- Register corresponding methods
- Register routes requiring authentication
- Attach event handlers to allow non-app links to work as normal
- Start Backbone.History
- Perform stored redirect if needed
- Check whether current page requires authentication
- Track pageview
Parameters
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
options |
object |
Properties
|
- Source:
(static) navigate(url, options)
Overrides Backbone.Router.prototype.navigate
- checks whether route is protected and if so, whether the user has the right permissions
- redirects to any stored redirect URL
- redirects to locked page if needed
- updates previous and current url stacks
- tracks pageview
- sets referrer if needed
- prevents invoking empty URLs
Parameters
Name | Type | Description |
---|---|---|
url |
string | URL to invoke |
options |
object | XXXX |
- Source:
(static) override(route, optionsopt)
Interrupt any currently invoked route and navigate to the route specified
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
route |
string | Route name |
|
options |
object |
<optional> |
this.navigate options |
- Source:
(static) previous(name, options)
Navigate to the app’s idea of the previous route
Parameters
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
string | object | Name of previous route |
||
options |
object | XXXX |
||
options.trigger |
boolean |
<optional> |
true | Whether to trigger the route |
options.replace |
boolean |
<optional> |
true | Whether to replace the URL in the history |
options.route |
boolean |
<optional> |
Route to use for URL |
|
options.params |
boolean |
<optional> |
Params to pass to Route reversing |
|
options.url |
boolean |
<optional> |
Explicit URL to use |
- Source:
(static) reverse(name, params) → {string}
Get URL for a route
Parameters
Name | Type | Description |
---|---|---|
name |
string | Route name |
params |
object | Additional params for route |
- Source:
Returns
URL for route
- Type
- string
(private, static) reverseRoute(route, name)
Add route URL pattern to reversed route registry
Parameters
Name | Type | Description |
---|---|---|
route |
string | URL pattern |
name |
string | Name of route |
- Source:
(static) reverseWithAuth(name, params) → {string}
Get protected URL for a route
Parameters
Name | Type | Description |
---|---|---|
name |
string | Route name |
params |
object | Additional params for route |
- Source:
Returns
URL for route
- Type
- string
(static) route(route, name, callback)
Register a route and update Backbone history
Overrides Backbone.Router.prototype.route
Parameters
Name | Type | Description |
---|---|---|
route |
string | URL pattern |
name |
string | Name of route |
callback |
function | Callback function for Backbone.Router.prototype.route |
- Source:
(static) setPrevious(name, ignoreopt)
Update previous route stack
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Route name |
|
ignore |
boolean |
<optional> |
Ignore this route |
- Source:
(static) storedRedirect()
Empty method to be overriden if stored redirect functionality is desired
- Source:
(inner) jQuery%removeRootCookie(name, optionsopt)
Delete cookie at the root path
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Cookie name |
|
options |
object |
<optional> |
Options to pass to jQuery.cookie |
- Source:
(inner) jQuery%rootCookie(name, value, optionsopt)
Set cookie operation at the root path
Parameters
Name | Type | Attributes | Description |
---|---|---|---|
name |
string | Cookie name |
|
value |
string | object | Cookie value |
|
options |
object |
<optional> |
Options to pass to jQuery.cookie |
- Source:
Returns
Cookie value
Events
window:on:click:a
Handle all triggerings of link elements
Allow normal link behaviour if
- Link has a target (and not siteinfo)
- Link is an email (mailto:)
- Link has a class of "external"
- if there is an external method, use that
- otherwise, allow link to load
- Link is a fragment identifier (#)
- Source: