Crowbar is a flexible routing system inspired by express, and director.
Example
var router = ; { // authenticate here} router; router; router;
Entering Routes
Called when a route is entered.
router; router;
You can also specify multiple enter handlers:
router;
API
Exiting Routes
Useful if you want to teardown a route before entering another.
router; router;router; // exit handler called
Just like enter handlers, you can specify multiple exit handlers
Route States
States are properties set by the router which may modify your application state. This is used specifically in mojo.js.
router; router; router;
Parameters
Just like express.js, you have the ability to create parameter loaders.
router; router; router
Naming Routes
router; router;
listeners
Kubrick comes with an HTTP listener by default, which is loaded automatically in the browser.
router.redirect(pathnameOrRouteName[, options], complete)
pathnameOrRouteName
- pathname or route name to redirect tooptions
- route name optionsquery
- route queryparams
- route params
complete
- called when redirected
router.add(routes)
adds new routes to the router
router.use(plugins...)
adds plugins to the router
router.location
The current location of the router
router;
Routes router.routes
Routes property
routes.find(query)
Finds a route based on the query.
router; console; // /home routeconsole; // /home route
location.query
query parameters on the location. Note that if the query changes, those changes will also be reflected in the HTTP url.
router; router;
location.params
similar to location.query
. location.params
are taken from the route parameters.
location.url
pathname + query params.
router; router;
location.pathname
just the pathname of the location
location.equals(location)
returns TRUE of the both locations are the same
location.redirect(pathname, options)
redirects the location
Mojo.js Usage
basic usage:
var mojo = app = ;app; approuter;