Class LocationRouterConstructor
A locationRouter is a router which navigates to the route defined in the URL and updates this URL
while navigating. It's a subtype of Emily's Router
Defined in: LocationRouter.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
destroy()
Remove the events handler for cleaning.
|
|
Get the currently set default route
|
|
parse(hash)
The function that parses the url to determine the route to navigate to.
|
|
setDefaultRoute(defaultRoute)
Set the default route to navigate to when nothing is defined in the url
|
|
start(defaultRoute)
When all the routes and handlers have been defined, start the location router
so it parses the URL and navigates to the corresponding route.
|
|
toUrl(args)
The function that converts, or serialises the route and its arguments to a valid URL.
|
Method Detail
destroy()
Remove the events handler for cleaning.
{String}
getDefaultRoute()
Get the currently set default route
- Returns:
- {String} the default route
{Array}
parse(hash)
The function that parses the url to determine the route to navigate to.
It has a default behavior explained below, but can be overriden as long as
it has the same contract.
- Parameters:
- {String} hash
- the hash coming from window.location.has
- Returns:
- {Array} has to return an array with the list of arguments to call navigate with. The first item of the array must be the name of the route. Example: #album/holiday/2013 will navigate to the route "album" and give two arguments "holiday" and "2013"
{Boolean}
setDefaultRoute(defaultRoute)
Set the default route to navigate to when nothing is defined in the url
- Parameters:
- {String} defaultRoute
- the defaultRoute to navigate to
- Returns:
- {Boolean} true if it's not an empty string
start(defaultRoute)
When all the routes and handlers have been defined, start the location router
so it parses the URL and navigates to the corresponding route.
It will also start listening to route changes and hashmark changes to navigate.
While navigating, the hashmark itself will also change to reflect the current route state
- Parameters:
- defaultRoute
{String}
toUrl(args)
The function that converts, or serialises the route and its arguments to a valid URL.
It has a default behavior below, but can be overriden as long as it has the same contract.
- Parameters:
- {Array} args
- the list of arguments to serialize
- Returns:
- {String} the serialized arguments to add to the url hashmark Example: ["album", "holiday", "2013"]; will give "album/holiday/2013"