<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>A Gentle Introduction</title> <script src="https://raw.github.com/flatiron/director/master/build/director.min.js"></script> <script> var author = function () { console.log("author"); }, books = function () { console.log("books"); }, viewBook = function(bookId) { console.log("viewBook: bookId is populated: " + bookId); }; var routes = { '/author': author, '/books': [books, function() { console.log("An inline route handler."); }], '/books/view/:bookId': viewBook }; var router = Router(routes); router.init(); </script> </head> <body> <ul> <li><a href="#/author">#/author</a></li> <li><a href="#/books">#/books</a></li> <li><a href="#/books/view/1">#/books/view/1</a></li> </ul> </body> </html>
Object
Router
Name | Description | |
---|---|---|
Router Constructor |
Name | Description | |
---|---|---|
async | Controls async routing. Use true or false. Default is false. | |
delimiter | Character separator between route fragments. Default is /. | |
every | A function (or list of functions) to call on every call to router.dispatch() when a route is found. | |
history | History object. | |
historySupport | If set to true and client supports pushState(), then uses HTML5 History API instead of hash fragments. See History API for more information. | |
notfound | A function to call if no route is found on a call to router.dispatch(). | |
params | URL Params. | |
recurse | Controls route recursion. Use forward, backward, or false. Default is false Client-side, and backward Server-side. | |
resource | An object to which string-based routes will be bound. This can be especially useful for late-binding to route functions (such as async client-side requires). | |
routes | Set of routes. | |
run_in_init | If html5history is enabled, the route handler by default is executed upon Router.init() since with real URIs the router can not know if it should call a route handler or not. Setting this to false disables the route handler initial execution. | |
scope | Route scope information | |
strict | If set to false, then trailing slashes (or other delimiters) are allowed in routes. Default is true. |
Name | Description | |
---|---|---|
configure | Given the flexible nature of director there are several options available for both the Client-side and Server-side. These options can be set using the .configure() method | |
dispatch | Dispatches the route handlers matched within the Routing Table for this instance for the specified method and path. | |
getRoute | Returns the entire route or just a section of it. | |
init | Initialize the router, start listening for changes to the URL. | |
insertEx | insert a callback that will only occur once per the matched route. | |
mount | Inserts the partial Routing Table, routes, into the Routing Table for this Router instance at the specified path. | |
on | Adds the route handler for the specified method and path within the Routing Table. | |
param | Adds a route fragment for the given string token to the specified regex matcher to this Router instance. See URL Parameters for more documentation. | |
setRoute | Remove a segment from the current route. |