I am looking to send data when changing the view using navigateByUrl like this:
this.router.navigateByUrl(url, {state: {hello: "world"}});
Once in the next view, my goal is to simply log the hello attribute like so:
constructor(public router: Router) { }
ngOnInit(): void {
console.log(this.router.getCurrentNavigation().extras.state.hello)
}
However, when I attempt to implement it this way, I encounter an error:
ERROR TypeError: Cannot read property 'extras' of null
at ProfileContactViewComponent.ngOnInit
Is there a better method for passing data between views? Any guidance would be greatly appreciated. Thank you.