Ionic 4 pass data from tab bar to all tabs

384 Views Asked by At

I have five tabs in my app. All these tabs require an id stored in local storage. So I want to get this id from local storage on the tab-bar page and send it to all tabs as the user clicks on respective tabs.

I don't want to use query params as exposing id in url is not safe

Edit I have used the angular router's navigationExtras with click event and it is working. But I am not sure this is the best way to this.

<ion-tab-button tab="tab1" (click)="tab1()">
      <ion-icon name="triangle"></ion-icon>
      <ion-label>Tab 1</ion-label>
    </ion-tab-button>



  tab1(){
    let navigationextas : NavigationExtras ={
      state : {
        user : 2
      }      
    }

    this.router.navigate(['tabs/tab1'], navigationextas)
  }
1

There are 1 best solutions below

0
Troy Thompson II On

Try using a shared service to set the id on click and populate the tabs