Dynamic rootPage based on Auth.isAuthenticated()


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";

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

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

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

Is this the correct way to get it work?

1 Like

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