I have defined some route data in my app routing module like below:
const appRoutes:Routes = [
{path: \'\', component: LoginComponent, data:[{PageName:
If you had statically routed using Router object like below:
{
path: '',
pathMatch: 'full',
component: NameComponent,
data: { variableName: 'variableValue' }
},
On ngOnInit() you can use ActivatedRoute object to recover the data you passed from Router definition:
ngOnInit() {
this.localVariable = this.route.snapshot.data['variableName'];
}
Obs: I am using Angular 5!