A module that allows one to easily map hash-based structures into callbacks. The router module is a singleton, offering one central point for all registrations of this type.
(kwArgs);
Parameter | Type | Description |
---|---|---|
kwArgs | undefined |
See the dojo/router/RouterBase reference documentation for more information.
var router = new RouterBase({});
router.register("/widgets/:id", function(evt){
// If "/widgets/3" was matched,
// evt.params.id === "3"
xhr.get({
url: "/some/path/" + evt.params.id,
load: function(data){
// ...
}
});
});
Defined by: dojo/router/RouterBase
Defined by: dojo/router/RouterBase
Defined by: dojo/router/RouterBase
Defined by: dojo/router/RouterBase
destroy
()
Defined by dojo/router/RouterBase
go
(path,replace)
Defined by dojo/router/RouterBase
A simple pass-through to make changing the hash easy, without having to require dojo/hash directly. It also synchronously fires off any routes that match.
Parameter | Type | Description |
---|---|---|
path | undefined | |
replace | undefined |
Returns: boolean | undefined
router.go("/foo/bar");
register
(route,callback)
Defined by dojo/router/RouterBase
Registers a route to a handling callback
Given either a string or a regular expression, the router will monitor the page's hash and respond to changes that match the string or regex as provided.
When provided a regex for the route:
When provided a string for the route:
Parameter | Type | Description |
---|---|---|
route | String | RegExp |
A string or regular expression which will be used when monitoring hash changes. |
callback | Function |
When the hash matches a pattern as described in the route, this callback will be executed. It will receive an event object that will have several properties:
|
Returns: Object | undefined
A plain JavaScript object to be used as a handle for either removing this specific callback's registration, as well as to add new callbacks with the same route initially used.
router.register("/foo/:bar/*baz", function(object){
// If the hash was "/foo/abc/def/ghi",
// object.bar === "abc"
// object.baz === "def/ghi"
});
registerBefore
(route,callback)
Defined by dojo/router/RouterBase
Registers a route to a handling callback, except before any previously registered callbacks
Much like the register
method, registerBefore
allows us to register route callbacks to happen before any previously registered callbacks. See the documentation for register
for more details and examples.
Parameter | Type | Description |
---|---|---|
route | String | RegExp | |
callback | Function |
Returns: undefined
startup
(defaultPath)
Defined by dojo/router/RouterBase
This method must be called to activate the router. Until startup is called, no hash changes will trigger route callbacks.
Parameter | Type | Description |
---|---|---|
defaultPath | undefined |
© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/router/RouterBase.html