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

I am on the homepage / home and want to navigate to kids / sheets.

we usually write this.route.navigate (['home']); but how do I write it from children to get the path as 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'}
]
      

Run code


+3


source to share


1 answer


this.router.navigate('unitsheet')

      

or

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

      



or you can use absolute paths

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

      

+4


source







All Articles