router


HTTP router which helps maintain application state.

Examples

Playground Example

Route Syntax

route.enter

route.name

Name of the route. It's recommended that you redirect with this incase the route ever changes.

route.states

The application state set by the route. This is used to change your UI state. See example above.

route parameters

Just like express.js, you have the ability to create parameter loaders.

nested routes

You can also nest routes.

API

router.redirect(pathnameOrRouteName[, options], complete)

  • pathnameOrRouteName - pathname or route name to redirect to
  • options - route name options
    • query - route query
    • params - route params
  • complete - called when redirected

router.add(routes)

adds new routes to the router

router.location

The current location of the router

router.bind("location", function () {
  // called whenever the location changes
});

location.query

query parameters on the location. Note that if the query changes, those changes will also be reflected in the HTTP url.

router.bind("location", function (err, location) {
  console.log(location.get("query.hello")); // blah
  location.set("query.hello", "world"); // gets reflected in the HTTP url
});

router.redirect("/home?hello=blah");

location.params

similar to location.query. location.params are taken from the route parameters.

location.url

pathname + query params.

router.bind("location", function (err, location) {
  console.log(location.get("url")); // /home?hello=blah
});

router.redirect("/home?hello=blah");

location.pathname

just the pathname of the location

location.redirect(pathname, options)

redirects the location