How Do I Implement Router In Canjs
I am taking help of the https://github.com/thinkadoo/Projects application. I have built a similar app with the help of this one. My application is using d3 charts instead of the on
Solution 1:
Here is an updated Fiddle that shows how routing works:
varRouter = can.Control({
defaults: {}
}, {
init: function() {
// this.element.html(can.view('#index', {}));
},
':type/:id route': function(data) {
console.log('Type:', data.type);
console.log('Id:', data.id);
}
});
can.route.ready(false);
newRouter('#content');
can.route.ready(true);
Basically, what you do is initialize your named placeholders and tell the controller that this should be handled by the route
processor. Now if you go to a URL like #!test/23
the data of the handler will contain a type
and id
property.
Post a Comment for "How Do I Implement Router In Canjs"