问题
I have a method add() on component that is called in this route: 'model/:id'.
Now, i want to add a new model, and for do this, need change the route to: 'model/0';
add(){
this.route.navigate(['model','0']);
}
I need to do this with the 'model' route dynamically, because the route can change, it's possible ?
回答1:
In your constructor import ActivatedRoute
construction(private route: ActivatedRoute, ...) {}
add() {
this.router.navigate(['../', '0'], {relativeTo: this.route});
}
回答2:
Try this
this.route.navigate(['model/0']);
回答3:
You can do it by this way
this.router.navigate(['/model', 0]);
For more information refer this
来源:https://stackoverflow.com/questions/40283562/how-to-change-only-params-of-route-in-angular2