I have an add() method for a component that is called in this route: 'model/:id' . Now I want to add a new model, and for this I need to change the route to: 'model/0' ;
add()
'model/:id'
'model/0'
add(){ this.route.navigate(['model','0']); }
I need to do this using the βmodelβ route dynamically, because the route may change, maybe?
try it
this.route.navigate(['model/0']);
You can do it this way
this.router.navigate(['/model', 0]);
For more information see this
In your importing ActivatedRoute constructor
ActivatedRoute
construction(private route: ActivatedRoute, ...) {} add() { this.router.navigate(['../', '0'], {relativeTo: this.route}); }