Using the router events I can see the navigation changes and the updated URL. But how do I get the actual router state (data, resolves, parameters, etc) from the URL. I tried using the ActivatedRoute
but this is only initialized once the component is initialized.
Current code:
@Component({...})
export class SecundaryMenuComponent implements OnInit, OnDestroy {
private titleSubject$: BehaviorSubject<string> = new BehaviorSubject<string>('');
public title$: Observable<string> = this.titleSubject$.asObservable();
private navSubscription: Subscription;
constructor(private router: Router, private activeRoute: ActivatedRoute) {
this.navSubscription = this.router.events.subscribe((event: NavigationEvent) => {
this.handleRoutingEvent(event);
});
}
ngOnInit(): void {}
ngOnDestroy(): void {
this.navSubscription.unsubscribe();
}
handleRoutingEvent(event: NavigationEvent) {
if (event instanceof NavigationEnd) {
this.titleSubject$.next(event.urlAfterRedirects);
}
}
}
So how can I access the active router state in the handleRoutingEvent
function?