如何使用 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) 有效。
2016-10-12 更新
还有一个stackoverflow问题:
2016-10-24更新
文档:
更新 2019-03-08
Angular 7.1 似乎有变化。在另一篇文章中有一个答案 how to solve it with Angular 7.1。请引用https://stackoverflow.com/a/38634440/42659 .
关于angular - 使用 Angular 2 路由器(版本 3)进行相对导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39124906/