How to change only route parameters in angular2?

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(){ this.route.navigate(['model','0']); } 

I need to do this using the β€œmodel” route dynamically, because the route may change, maybe?

0
angular angular2-routing
source share
3 answers

try it

 this.route.navigate(['model/0']); 
0
source share

You can do it this way

  this.router.navigate(['/model', 0]); 

For more information see this

0
source share

In your importing ActivatedRoute constructor

 construction(private route: ActivatedRoute, ...) {} add() { this.router.navigate(['../', '0'], {relativeTo: this.route}); } 
0
source share

All Articles