The official documentation tells to use title property of Route to set page title. https://angular.io/guide/router#setting-the-page-title
Each page in your application should have a unique title so that they can be identified in the browser history. The Router sets the document's title using the title property from the Route config.
But I get this error:
Type '{ path: string; title: string; component: typeof SecondComponent; }' is not assignable to type 'Route'. Object literal may only specify known properties, and 'title' does not exist in type 'Route'.
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { SingleComponent } from './single/single.component';
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { FirstComponent } from './first/first.component';
import { SecondComponent } from './second/second.component';
import { ChildAComponent } from './child-a/child-a.component';
import { ChildBComponent } from './child-b/child-b.component';
const routes: Routes = [
{ path: 'first', component: FirstComponent, children: [
{ path: 'child-a', component: ChildAComponent },
{ path: 'child-b', component: ChildBComponent },
]},
{ path: 'second', title: 'Second page title', component: SecondComponent }, // here an error
{ path: 'single', component: SingleComponent },
{ path: '', redirectTo: '/first', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }