How to conditionally set root page in Ionic 4

Hope it helps…

import {  Platform, NavController } from 'ionic-angular';
import { Router } from '@angular/router';

export class MyApp {

constructor(private platform: Platform, private router: Router) {
    platform.ready().then(() => {
      
    if(someCondition) { // if not login
      this.router.navigateByUrl('/');
   /*
   this will also work
   this.navCtrl.goRoot('/');
  */
    } else { // if login
     this.router.navigateByUrl('/app');
   /* this will also work
    this.navCtrl.goRoot('/app');
   */
    }
      
    });
  }
}
5 Likes