I need to pass data along with the route from one component to another and retrieve it in the other component's constructor:
Passing data:
this.router.navigate(['/coaches/list'], {
state: { updateMessage: this.processMessage },
replaceUrl: true
});
Retrieving data in the constructor:
if (this.router.getCurrentNavigation().extras?.state != null) {
this.successMessage = this.router.getCurrentNavigation().extras.state;
}
The issue I am facing is that initially, extras.state is undefined without any data. It only gets populated when I close the dialog button on the other component.
How can I resolve this problem as I keep getting the ERROR TypeError: Cannot read property 'extras' of null during the initial loading?