I want to set up routing with CanJS so that depending on what url I hit, some corresponding control is set up. My problem is trying to find a way of expressing a default route to listen for in the control: "If none match, then do this". Any tips on doing this?
This is my code so far. Seems to work for urls like /#!/plant/1/day/3
and /#!/plant/1
, but not for /#!
or /
can.route('plant/:plant_id/day/:day', {});
can.route('plant/:plant_id', {});
can.route('', {});
var Router = can.Control({}, {
init : function () {},
"{can.route}" : function (route, event, newVal, oldVal) {
console.log('Init default control');
},
"{can.route} plant_id" : function (route, event, newVal, oldVal) {
console.log('Init plant control');
},
"{can.route} day" : function (route, event, newVal, oldVal) {
console.log('Init day control');
}
});
P.S. I actually managed to do it using the Can.Control.route plugin by doing this:
"route" : function (route, event, newVal, oldVal) {
console.log('route Default route', arguments);
}
But the route plugin seems to both set up routes and react to them, and I wanted to know how to do this without the specific plugin.