Dynamic rootPage based on Auth.isAuthenticated()


#1

Hi,

Initially, this issue was a bug report trying to dynamically set the root page for my application. Now, I have already solved.

Perhaps this example will be useful to someone:

import {Component} from '@angular/core';
import {Platform} from 'ionic-angular';
import {StatusBar, Splashscreen} from 'ionic-native';
import {HomePage} from '../pages/home/home';
import {LoginPage} from "../pages/login/login";
import {Auth} from "@ionic/cloud-angular";

@Component({
    template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
    public rootPage;

    constructor(platform: Platform, public auth: Auth) {
        platform.ready().then(() => {
            StatusBar.styleDefault();

            if (this.auth.isAuthenticated()) {
                this.rootPage = HomePage;
            } else {
                this.rootPage = LoginPage;        
            }   
            Splashscreen.hide();     
        });
    } 
}

Is this the correct way to get it work?


#2

I’m not sure this the best way. But, it worked for me.
Thanks for sharing this.:grinning: