How to get RouteParams from parent component as well as child routes
export const routes: Routes = [ { path: '', redirectTo: 'list', pathMatch: 'full' }, { path: 'list', component: UsersComponent }, { path: ':id', component: UserDetailComponent, children: [ // { path: '', redirectTo: 'overview', pathMatch: 'full' }, { path: 'overview', component: UserInfoComponent }, { path: 'specs/:id', component: UserProfileComponent } ] } ];
In component
export class UserDetailComponent implements OnInit { constructor(private route: ActivatedRoute) { } ngOnInit() { this.route.parent.params.subscribe( (c) => { console.log(c['id']); }); this.route.params.subscribe(params => { console.log(params['id']); }); } }
But I always get undefined when my route is activated. kindly help solve this problem?
Thanks in advance.
source share