How do I listen for and react to a blank route using {can.route}?

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.

以上就是How do I listen for and react to a blank route using {can.route}?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏