I have a parent module with two sibling components. I just need to load the second sibling component when am call a method in sibling 1.I am using router.navigate function to do this but the component view is not loading only route changes in browser's address bar.
parentcomponent
siblingcomponent1
siblingcomponent2
parentcomponent.routing.module.ts
parentcomponent.routing.module.ts:-
{ path: '', redirectTo: 'sibling1', pathMatch: 'full' },
{
path: 'sibling1',
component: siblingcomponent1,
},
{
path: 'sibling2',
component: siblingcomponent2,
},
parentcomponent.ts:-
showSibling1 = false;
showSibling2 = false;
ngOnInit() {
switch(this.router.url) {
case 'sibling1': {
this.showSibling1 = true;
break;
}
case 'sibling2': {
this.showSibling2 = true;
break;
}
}
parentcomponent.html:-
<app-siblingcomponent1
*ngIf="showSibling1"
></app-siblingcomponent1>
<app-siblingcomponent2
*ngIf="showSibling2"
></app-siblingcomponent2>
app-siblingcomponent1.ts:-
method() {
// here the route changes in browser address bar but component is not loading why?
this.router.navigate(['sibling2']);
}
app.component.html :-
<router-outlet></router-outlet>