How to get children of route

202 views Asked by At

How can I get children object of the 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 }
        ]
    },
    ...
]

And Component

export class AsideComponent implements OnInit {
    constructor(private router: Router) {
        let children = this.router... ? // <-----
    }
}

I have this.router, how can I get the childrens of current state?

1

There are 1 answers

2
Radovan Skendzic On

You need https://angular.io/api/router/ActivatedRoute

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