如何在组件中使用Router
从/questions/123/step1
相对导航到/questions/123/step2
,而无需串接并指定/questions/123/
?
我在下面添加了自己的答案.请随时提出更好的答案.;-)我想有更好的方法.
如何在组件中使用Router
从/questions/123/step1
相对导航到/questions/123/step2
,而无需串接并指定/questions/123/
?
我在下面添加了自己的答案.请随时提出更好的答案.;-)我想有更好的方法.
在做了更多的研究后,我发现
this.router.createUrlTree(['../step2'], {relativeTo: this.activatedRoute});
和
this.router.navigate(['../step2'], {relativeTo: this.activatedRoute});
第一种方法(Router.createUrlTree API)对我不起作用,即什么都没发生.第二种方法(Router.navigate API)有效.
However, second approach uses NavigationExtras
(second argument) which is documented with @experimental
. Hopefully there won't be big changes with the next release again... 和 NavigationExtras
will be stable.
任何其他建议/方法,请毫不犹豫地回答我的上述问题.
Update 2016-10-12
还有另一个问题:
Update 2016-10-24
文档:
Update 2019-03-08
看起来7.1的Angular 发生了变化.在另一篇文章中,有一个答案是如何用Angular 7.1解决这个问题.请参考https://stackoverflow.com/a/38634440/42659.