new Router(controller, routes)
Parameters:
Name | Type | Description |
---|---|---|
controller |
Object | |
routes |
Object |
Example
var controller = {layout: ...};
var router = new Router(controller, {...routes})
router.parse(controller.layout);
router.route();
Members
(static) base :String
Base subpath if app is not running on root
Type:
- String
(static) rewrite :Boolean
wheter urls should be rewritten or not (if not uses query string ?route=path/to/route)
Type:
- Boolean
Methods
(static) fetch(routes, path)
finds a specific path in defined routes
Parameters:
Name | Type | Description |
---|---|---|
routes |
Object | |
path |
String |
(static) generate(path)
generates a full url to a specific route taking rewrite rules into account
Parameters:
Name | Type | Description |
---|---|---|
path |
String | for which a full url should be generated |
(static) get(url)
generates the corresponding path of the current or a specified url, stripping out the domain and base path
Parameters:
Name | Type | Description |
---|---|---|
url |
String | (optional) |
destroy()
destroy current router instance
parse(container)
parses a dom container for href's, and binds click events to internal links
Parameters:
Name | Type | Description |
---|---|---|
container |
DOMElement |
route()
fetches route and calls controller, should be called when first instantiating the router
to(path)
switches to a specific path
Parameters:
Name | Type | Description |
---|---|---|
path |
String | that should be switched to |