如何让孩子走路

时间:2017-08-29 13:29:58

标签: angular angular-router

如何获取路由器的子对象?

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... ? // <-----
    }
}

我有这个。我怎么能得到当前状态的孩子?

1 个答案:

答案 0 :(得分:1)

您需要https://angular.io/api/router/ActivatedRoute

export class AsideComponent implements OnInit {
    constructor(private router: ActivatedRoute) {
        let children = this.router.children
    }
}