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.routewithout a template:If you give
can.routea template, you can make pretty URLs:Listening to events
Because
can.routeis 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.urltakes a set of properties and makes a URL according tocan.route's current route.can.route.linkdoes 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.