How is routing with components done with canjs?
I have following example
can.Component.extend({
tag: "router",
events: {
"{can.route} id bla": function(route, event, id, bla) {
console.log("route", id, bla);
}
}
});
How can I match the specific route? For example page/2/foo.
The route is defined as
can.route(":page/:id/:bla", {page: "", id: "", bla: ""});
The trick to do routing in components is to not do routing in components. Instead, with something like
You pass
can.route
as a state object. With a main view like:rendered like
can.view('main', { state: can.route })
your component then just checks those attributes:With a view that initializes its child components: