Pass data between two pages using the setRoot function

I’m trying to pass an object as a parameter of the setRoot function this way, data);

and then in TabsPage.ts I try to retrieve the object like this:

userProfile: any;

constructor(public navParams: NavParams) {
    this.userProfile = this.navParams.get("data");
    console.log("tabspage param", this.userProfile);

But this.userProfile is undefined, how do I correctly retrieve the object that I pass as a parameter?

That’s actually the wrong question. What you need to ask is how you properly pass things, and this is partially why using names like “data” in actual app code is harmful, because it makes you gloss over how things are named. If you had instead called it userProfile, you might have been more likely to think “how on earth is anybody going to know what that property is called if I just pass it in naked?”. The second argument to setRoot() is an object containing the things you want to pass:

setRoot(TabsPage, {userProfile: profile});

Did you solve it finally ? because I’m facing the same problem

1 Like