Router.Hashbang Class
Methods
getRoute
()
Object
Returns:
{ href: "http://localhost/#/mypath/dayone?user=1", origin: "http://localhost" path: "/#/mypath/dayone?user=1", // (href - origin) cleanPath: "/mypath/dayone", //non hash routes hash: "#/mypath/dayone?user=1", //window.location.hash cleanHash: "#/mypath/dayone" parameters:{} //url parameter as object }
getUrlParam
-
url
adapted from http://stackoverflow.com/a/1099670/425226
Parameters:
-
url
String/#/mypath/dayone?user=1&name=fred
init
()
call this after setting router.set({}) if you wish to do an immediate evaulation of url
is
-
pattern
Check whether the url matches a pattern - removes any parameters in the url to check for a match
Parameters:
-
pattern
String
Returns:
Example:
Firebrick.router.is("#/completed") // returns true or false
Firebrick.router.is("/completed") // returns true or false
onHashChange
-
callback
-
config
Call a function when the hash changes on the site use Firebrick.route:set
Parameters:
-
callback
Function -
config
Objectconfig that was used for this callback - optional
Returns:
jQuery object
Example:
Firebrick.router.onHashChange(function(){
//something happens
})
set
-
routes
set route definitions
Parameters:
-
routes
Object | Function- if function then the function is called regardless of route
Example:
Firebrick.router.set({
"users/abc": {
require:["file1", "file2"],
callback: function(){}
},
"contact": function(){}
defaults: function(){} //defaults pattern - fallback
})
Firebrick.router.set(function(){}) //call function regardless of route
Properties
_initialised
Boolean
used to see whether document events for the history API have already been set
Default: false