How to change only params of route in angular2?

故事扮演 提交于 2019-12-08 11:18:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!