gpt4 book ai didi

Angular2 : how do i navigate to children from component. ts

转载 作者:太空狗 更新时间:2023-10-29 18:20:20 24 4
gpt4 key购买 nike

我在主页/home 上,想导航到 children/unitsheet

通常我们这样写 this.route.navigate(['home']);但是我如何从 child 那里写它以获取路径 localhost:4200/home/unitsheet

const ROUTER_DATA: Routes = [
{ path:'login', component: LoginComponent},
{ path:'home', component: HomeComponent, children: [
{ path:'unitsheet', component: unitComponent},
]},
{ path:'', redirectTo:'login', pathMatch: 'full'}
]

最佳答案

this.router.navigate('unitsheet')

<a [routerLink]="'unitsheet'">unitsheet</a>

或者你可以使用绝对路径

<a [routerLink]="'/home/unitsheet'">unitsheet</a>

关于Angular2 : how do i navigate to children from component. ts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43558083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com