本文介绍了Angular:如何通过使用Navigation方法从父组件导航到子路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的html rouerLink:
Here is my html rouerLink:
<a [routerLink]="['create']">Create</a>
-正常工作.
在按钮上单击我的呼叫方式是:但不起作用.
on button click I am calling the same as: But not works..
navigateTo(page) {
this.router.navigate(['create']); //not works
}
任何人都可以帮助我,我在这里真正想念的是什么?
Any one help me, what is really I am missing here?
更新
我正在从父母那里导航到孩子
I am navigating from parent to child
这是路线:
{
path: 'contentPlaceholder',
data: { showNavi: true },
component: ShellContentPlaceholderComponent,
children : [
{
path: 'view',
data: { showNavi: false },
component: ShellContentViewPlaceholderComponent,
},
{
path: 'create',
data: { showNavi: false },
component: ShellContentCreatePlaceholderComponent,
},
{
path: 'edit',
data: { showNavi: false },
component: ShellContentEditPlaceholderComponent,
},
{
path: 'update',
data: { showNavi: false },
component: ShellContentUpdatePlaceholderComponent,
}
]
}
推荐答案
尝试通过设置 relativeTo
值为当前路线:
Try by setting relativeTo
value to current Route:
constructor(private router: Router, private route: ActivatedRoute) {}
然后:
this.router.navigate(['./create'], { relativeTo: this.route });
这篇关于Angular:如何通过使用Navigation方法从父组件导航到子路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!