javascripturl-routingcanjscanjs-routing

can.routing : triggering a change to go from #!/foo/bar to #!/foo


I am trying to understand CanJS' routing. So far, I have the following routes set up.

can.route('plant/:plant/', {
    plant : undefined,
    day : undefined
});
can.route('plant/:plant/day/:day', {
    plant : undefined,
    day : undefined
});

I have no listeners set up yet, as I am just trying this out in the console. The following works fine:

can.route.attr({plant : 1}) // ==>  #!plant/1/
can.route.attr({plant : 1, day : 3}) // ==>  #!plant/1/day/3

But after I have done this, I would like to trigger an event to go "up" in the hierarchy, back to the #!/plant/1 level. I tried doing can.route.attr({plant : 1, day : undefined}), but that did not do anything. can.route.attr({plant : 1, day : null}) just resulted in #!plant/1/day/null.

So how do I "reset" the route to now "know" anything about which day it is?


Solution

  • After I learned that can.route is essentially what is known as an Observable I understood that what I was actually trying to do is remove an attribute. And to do that, all one has to do is

    can.route.removeAttr('day') // ==> #!plant/1/