I have 2 components, a parent and a child. The same parent component should load on 2 different routes, let's say route1 and route2. The parent component checks which route was used and sets a boolean regarding (isRoute1). The child component gets this boolean as an Input and render HTML regarding. See the skeleton code below.
Let's say first I open route1 in the browser. I could see 'Parent init' and 'Child init' texts in the console and the child component renders 'ROUTE1'. Everything is working as expected. Next, I navigate to route2 in the browser (directly from route1) and I have got some unexpected results. In the console, nothing shows up (so the OnInits didn't trigger) however the child rendered 'ROUTE2'. Why Angular didn't trigger the OnInit() function? How could I achieve that? I thought on route change the parent component will reload so the child.
// Parent component's TS
isRoute1: boolean;
ngOnInit(): void {
console.log('Parent init')
this.router$.pipe(debounceTime(1), untilDestroyed(this)).subscribe(route => {
this.isRoute1 = route.params.id === 'route1';
});}
// Parent component's HTML
<child-component [isRoute1]="isRoute1"></child-component>
// Child component's TS
@Input()
isRoute1: boolean;
ngOnInit(): void {
console.log('Child init')
}
// Child component's HTML
<div *ngIf="isRoute1; else route2"> ROUTE1 </div>
<div #route2> ROUTE2 </div>
routes? Do you have router outlets?export const PAGE_ARCHITECT_COMPONENTS: ArchitectComponentsMap = { PARAM1: MyComponent, PARAM2: MyComponent, ...}