Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update a page title statically(Angular)
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [{
path: 'home',
component: HomeComponent,
children: [
{ path: '', redirectTo: 'email', pathMatch: 'full', data: { title: 'Email' } },
{ path: 'email', component: EmailListComponent },
]
}];
@NgModule({
declarations: [],
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
export class HomeComponent {
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
map(() => this.actRoute),
map((route) => {
while (route.firstChild) route = route.firstChild;
return route;
}),
filter((route) => route.outlet === 'primary'),
mergeMap((route) => route.data), // only take data from routes
distinctUntilChanged(isEqual),
takeUntil(this.destroy$)
)
.subscribe((event) => {
console.log(event) //
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment