Issue
In the latest version of Angular 7.2.6, I'm trying to pass data in router itself
this.router.navigate(['other'], {state: {someData: 'qwert'}}
In the OtherComponent
file, this.router.getCurrentNavigation()
always return null
Angular Docs - getCurrentNavigation
Solution
You're calling the method getCurrentNavigation
too late. The navigation has finished.
You need call the getCurrentNavigation
method inside of the constructor:
constructor(private router: Router) {
this.name = this.router.getCurrentNavigation().extras.state.someData;
}
Or if you want to access the navigation in ngOnInit
you can do following:
ngOnInit() {
this.name = history.state.someData;
}
Answered By - Batajus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.