如何仅更改angular2中的路线参数? [英] How to change only params of route in angular2?

查看:67
本文介绍了如何仅更改angular2中的路线参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此路由中调用的组件上有方法add():'model/:id'. 现在,我想添加一个新模型,为此,需要将路由更改为:'model/0';

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 ?

推荐答案

在构造函数中导入ActivatedRoute

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

这篇关于如何仅更改angular2中的路线参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆