I have a route registered with some data:
const routes: Routes =
[
{path: \'my-route\', data: { title: \'MyTitl
. So it looks like that this is the intended behaviour.However I still think that my answer below can be useful to anyone who is trying to accomplish the same thing.
import { Component, OnInit } from '@angular/core';
import { Router, RoutesRecognized } from '@angular/router';
@Component({...})
export class MyComponent implements OnInit {
private routeData;
constructor(private router: Router) { }
ngOnInit() {
this.router.events.subscribe((data) => {
if (data instanceof RoutesRecognized) {
this.routeData = data.state.root.firstChild.data;
}
});
}
}
doing this way this.routeData
will hold the route data that I needed (in my case the page title
).