I have two URLs on my site
- https://example.com -> Main page
- https://example.com/test -> Inner Page
Header and Footer are different for both URLs.
On the inner page, I add the link to go main page (https://example.com) for this I used the routerLink="/" the contents are loaded correctly but the header and footer contents are not updated to the main page still keep the inner page.
My Analysation is Header component ngInit is not triggered. Sample codes I have added the RouterModule in SharedModule.ts
app.component.ts
<app-header></app-header>
<router-outlet></router-outlet>
<app-footer></app-footer>
header.component.ts
this.router.events.pipe(takeUntil(this.onDestroy$)).subscribe((events) => {
if (events instanceof NavigationEnd) {
if () {
//main page logic
} else {
//inner page logic
}
});
Some reference threads are: https://stackoverflow.com/a/45865355/8119756
Thanks in advance.