1

I am passing data from route with state but component is receiving it only first time, how I can listen it to every time component is visible.

 const navigationExtras: NavigationExtras = {
  state: { billingInfoData: billinfoData },
};

this.router.navigate(['/tabs/mytab'], navigationExtras);

receiving code is like below in constructor

this.route.queryParams.subscribe(data => {
      console.error(data);
      this.setSubtitle(data);

      if (
        this.router.getCurrentNavigation() &&
        this.router.getCurrentNavigation().extras.state
      ) {

      console.error(this.router.getCurrentNavigation().extras.state);

      }
    });
nirmal
  • 2,143
  • 1
  • 19
  • 29

1 Answers1

0

You could try to subscribe to NavigationEnd event from your router and add your state in a hook like ngOnInit in a component that outlive your mytab components:

this.router.events.subscribe( (navEvent)=> {
  if (navEvent instanceof NavigationEnd && navEvent.url.includes('/tabs/mytab')) {
    this.router.getCurrentNavigation().extras.state = navigationExtras;
  }
});