I’ve had quite a time trying to work with child routes and accessing the currentInstruction object so that I can navigate properly to other child routes. The problem is coming from the fact that I’m injecting the router into the class e.g. import { Router } from 'aurelia-router';
. In that view model I’m wanting to navigate to another child route but and was trying to use this.router.navigateToRoute and then trying to grab the this.router.currentNavigation
but is always null. I finally fingured out that you need to grab the router object from the route components activate lifecycle method which has the actual current child router object.
I thought I’d share this for anyone having similar issues.
export class MyViewModel {
activate(params, routeConfig, navigationInstruction){
this.navigationInstruction = navigationInstruction;
}
someMethod(){
this.navigationInstruction.router.navigateToRoute( this.navigationInstruction.config.name );
}
}