Route parameters issue


#1

Hello

Is it possible to read can route data values in view model?

Let’s say I have
can.route.register(’{page}’);
can.route.register(’{page}/{resource}’);
can.route.register(’{page}/{resource}/{resourceId}’);
can.route.start();

When I go to the first page which uses can.route.data.resource it’s all good. When I to the the second page can route detects the change of the hash and invokes the logic on the first page before page is changed.

Here’s the JS Bin example:

You can see that categoryPromise is called when you enter and when you leave categories page.
Can I read the route attributes somehow? Or do I have to pass route attributes around like that and then use this.resource in view model.


#2

I believe this is an example of a bug (and solution) described here:

Essentially, we don’t order the underlying observation update right in this situation. However, this does work if the value comes from a binding as shown in this JSBin:

So yeah, you should pass values around if getters are going to be doing side effects.

There’s other ways around this that I’ll write up in another JSBin when I get some more time.