Routing
Routing
can.route is the core of CanJS's routing functionality. It is a special
Observe that updates window.location.hash
when its properties change and
updates its properties when window.location.hash
changes. You can give
can.route
a template to translate URLs into property values, but if no route
is provided, it just serializes the route into standard URL-encoded notation.
Here is how you might use
can.route
without a template:If you give
can.route
a template, you can make pretty URLs:Listening to events
Because
can.route
is an Observe, you can bind to it just like normal Observes:You can listen to routing events in Controls with the route event:
Making URLs and links
can.route.url
takes a set of properties and makes a URL according tocan.route
's current route.can.route.link
does the same thing ascan.route.url
, but it returns an anchor element (in string form) ready to be inserted into HTML. You can also specify extra propertires to be set on the element.