Child router and sibling navigation

We have a parent route defined with /home /other1 and /other2. /home is the default route.
/home also has routes defined /r1 /r2 /r3 where /r1 is the default route. When the user starts the app he is now on /home/r1. When the user takes some action we want to navigate the user to /r2. The only way I can get it to work is by using the code below:
this.router.load(‘r2’,{ context: this.context.parent });

The question is why the context is required and why is “parent” the correct context. I would expect below to work:
this.router.load(‘r2’);
or possibly:
this.router.load(‘./r2’);
to indicate it is a sibling route and not another child route.

I would also expect the route context to point to the current context, but somehow context.parent point to the current context. We are using the import { IRouter, route } from ‘@aurelia/router’;

Am I missing something obvious? I have looked at this: Child routing playbook | The Aurelia 2 Docs specifically point 4 and just using “this.context” does not work (for me).

Hi @magnusdanielson! The changes in the path syntax are being tracked here: Router path interpretation changes · Issue #2256 · aurelia/aurelia · GitHub

In the meantime, here is some additional information about the context. Contexts in Au2 router are like the child routers in Au1. The difference being that they are not exactly a (child) “router”; rather, they provide contextual information to the router. As in Au2, the router is a singleton and there are no child routers, this contextual information is essential for the router to find the right component and make navigation. For more about routing context, you can refer to the docs:

3 Likes

@magnusdanielson Have a look at the PR feat(router): context-router by Sayan751 · Pull Request #2368 · aurelia/aurelia · GitHub if that suffices for your use-cases.

Thank you! Will do asap.