1

I'm using the following code to pass data to a route:

this.router.navigateByUrl('/myurl/goes/here', { state: { data: someData });

Now in the component i navigate to, i use the following code to get the data i passed from the first component.

this.incomingData = window.history.state.data;

Now the issue arrises when I reload the second component (Component B), i get an error telling my the data I passed to it is now undefined. (this.incomingData becomes undefined).

Is what am doing the correct way to pass and receive data between components or am I doing something wrong ?

marvin ralph
  • 1,100
  • 3
  • 23
  • 43
  • 1
    here is the link it will help you how to pass data and get it in another component https://stackoverflow.com/questions/44864303/send-data-through-routing-paths-in-angular – kushal shah Dec 16 '19 at 17:35

1 Answers1

-1

Use angular ActivatedRoute service in component, that you navigate to

 constructor(activeRoute: ActivatedRoute) {

    // this.activeRoute.snapshot.data
    console.log('Route Data', this.activeRoute.snapshot.data)
  }
miladfm
  • 1,508
  • 12
  • 20