Ionic 3 - If session exists load tabs page instead of signup page

367 views Asked by At

When the user opens up the app if there is already a session object then the app should open up the tabs page instead of the signup.

Whats the best way to achieve this. I am using the ionic-start-super template. https://github.com/ionic-team/ionic-starter-super

I was thinking to just check if a session exists in the constructor of the signup page, if it does then it will set the tabs page to be the root like below.

this.storage.get('user').then((user) => {

            this.user = user;

            if (this.user) {
                this.navCtrl.setRoot(TabsPage);

            }
});

Im wondering if there is a more efficient way.

1

There are 1 answers

0
Mithun Sen On

you can use your script inside of ionViewCanEnter() like this -

ionViewCanEnter() {
    this.storage.get('user').then((user) => {
        this.user = user;
        if (this.user) {
            this.navCtrl.setRoot(TabsPage);
        }
    });
}