如何获取路由器的子对象?
const appRoutes: Routes = [
{
path: 'parameters',
component: AsideComponent,
children: [
{ path: '', component: ParametersComponent },
{ path: 'crypto-accounts', component: ParametersCryptoAccountsComponent },
{ path: 'withdrawal-accounts', component: ParametersWithdrawalAccountsComponent },
{ path: 'add-withdrawal-account', component: ParametersAddWithdrawalAccountComponent }
]
},
...
]
和组件
export class AsideComponent implements OnInit {
constructor(private router: Router) {
let children = this.router... ? // <-----
}
}
我有这个。我怎么能得到当前状态的孩子?
答案 0 :(得分:1)
您需要https://angular.io/api/router/ActivatedRoute
export class AsideComponent implements OnInit {
constructor(private router: ActivatedRoute) {
let children = this.router.children
}
}