Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : CanJS - Default route called when route is not default

$
0
0
http://codepen.io/anon/pen/DjGEk

Open that pen and watch your console to see what's happening when you click back and forth between the buttons.  When you change the project with

can.route.attr('project', 5);

it adds the project param to the current set of route attributes.  The route object changed, but the can.route.attr('route') hasn't been updated, yet.  Once the can.route.attr('route') gets updated to ':project', it works as expected.

When you use 
can.route.attr('project', 5);
it adds the project route to the current route's parameters first.  Can.route then checks to see if the new set of params match a known route, then it runs again with the updated route param.

When you change your route, you may want to try replacing the entire route. Using
can.route.attr( {'project': 5} , true);
replaces everything in the route with the passed object and updates the route attr.

can.route.attr({}, true);
replaces the route contents with an empty object (the default route).

http://codepen.io/anon/pen/ztnDj -> Updated to show how it works when replacing all route params.


There's my shot at it.  Hope it helped.

Viewing all articles
Browse latest Browse all 3491

Trending Articles