Constructor
new Router()
Example
let router = new Router()
// Set up a couple of routes, each with a URL matching regexs and a route name
// matches http://<domain>/<path> and http://<domain>/<path>#
router.addRoute(/^$/, 'default')
// matches http://<domain>/<path>#blog/1123/app/abc-123
router.addRoute(/^blog\/([0-9]+)\/app\/([0-9a-z\-]+)$/, 'blog-app')
// Listen for the route
router.addListener('blog-app', (routeName, hash, ...regexMatches, ...parameters) => {
// If this was an event triggered by routing to #blog/1123/app/abc-123 then:
// `routeName` would be 'blog-app'
// `hash` would be 'blog/1123/app/abc-123'
// `regexMatches` would be ['1123', 'abc-123']
// `parameters` is empty in this example but could be any number of extra items in the route (see `addRoute`)
})
// Start must be called in order to begin routing
router.start()
Members
cleanedUp :boolean
Type:
- boolean
routes :Array.<Router>
Type:
- Array.<Router>
Methods
addRoute(regex, eventName, …parameters)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
regex |
RegExp | The regular expression that matches the incoming hash changes | |
eventName |
string | The event name used when triggering | |
parameters |
* |
<repeatable> |
Parameters passed without modification to listeners after the event name and matches |
start()
This must be called in order to start routing.