Constructor
# new AdmRouter(config)
Create a Router.
Parameters:
Name | Type | Description |
---|---|---|
config |
object
|
Configuration object of router |
Example
//Example 1:
const config = {
root: '',
routes: [{path, config, handler}],
listen: true,
change: () => {}
fail: () => {}
initComplete = () => {} || null;
};
const router = new AdmRouter(config);
//Example 2:
const router = new AdmRouter({root: ''});
router
.add("/", (routeData) => { ... }, configData)
.add("/*", (routeData) => { ... }, configData)
.add("*", (routeData) => { console.log("404"); })
.listen()
Methods
# _callRouteHandler(matchData)
[Private] Handle route handlers.
Parameters:
Name | Type | Description |
---|---|---|
matchData |
string
|
result of match function |
# add(route, config, handler) → {object}
Add a route.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
route |
string
|
Expression of a route. For a catchall or 404 error route add an asteric ("*") as last route | |
config |
object
|
null | Configuration of a route (optional) |
handler |
function
|
null | Handler by matching of a route (optional) |
The router instance
object
# match(path, data) → {object}
Match a route.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
path |
string
|
Path from an url | |
data |
string
|
null | ThroughPass data (optional) |
Match data from route
object
# navigate(path, data, title, replace)
Match a route.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
path |
string
|
Path to navigate | |
data |
string
|
null | ThroughPass data (optional) |
title |
string
|
Title from website (optional) | |
replace |
boolean
|
false | History replace - default false (optional) |
# remove(route) → {object}
Remove a route.
Parameters:
Name | Type | Description |
---|---|---|
route |
string
|
Expression of a route |
The router instance
object