导航相对与角2路由器(第3版)

如何从/questions/123/step1使用Router无字符串连接,并指定一个/questions/123/组件内导航相对于/questions/123/step2?导航相对与角2路由器(第3版)

我在下面添加了一个自己的答案。请随时提出更好的答案。 ;-)我想有更好的方法。

回答:

做一些更多的研究后,我碰到一个

this.router.createUrlTree(['../step2'], {relativeTo: this.activatedRoute}); 

this.router.navigate(['../step2'], {relativeTo: this.activatedRoute}); 

第一种方法(Router.createUrlTree API),我没有工作,也就是什么都没有发生。第二种方法(Router.navigate API)的作品。

但是,第二种方法使用NavigationExtras(第二个参数),其记录在@experimental中。希望下一次发布的版本不会有太大变化......并且NavigationExtras将会保持稳定。

任何其他建议/方法,请不要犹豫回答我上面的问题。

更新2016年10月12日

还有一个计算器问题,以及:

  • How do I navigate to a sibling route

更新2016年10月24日

文档:

  • Routing & Navigation (Relative Navigation)

回答:

您可以在下面使用,

假设questions加载到您的主router-outlet

this.router.navigate([ 

'/',

{

outlets: {

primary: [

// below may be replaced with different variables

'questions',

'123',

'step2'

]

}

}

])

希望这有助于!

回答:

首先,注入上构造路由器& ActivatedRoute

constructor(private route:ActivatedRoute,private router:Router) { } 

然后使用Click事件:

onEditClick(){ 

this.router.navigate(['edit'],{relativeTo:this.route});

您导航到预期page.In我的方案,我想去配方/ 1编辑食谱。 http://localhost:4200/recipes/1/edit

以上是 导航相对与角2路由器(第3版) 的全部内容, 来源链接: utcz.com/qa/260370.html

回到顶部