Push ionic screens 3

0

I'm using this command this.navCtrl.push('HomePage'); to navigate between pages in ionic 3 but I need to make it not appear like this:

Icannotgivetheguythechancetogobacktothenextscreen.

InfactwhatIneedisaif()iftheuserisalreadyloggedintorootPageitisoneifitisnotanother.

Howtodothis?

Itriedtodothis:

exportclassMyApp{rootPage:any=LoginPage;constructor(publicnavCtrl:NavController,privatestorage:Storage,platform:Platform,privatestatusBar:StatusBar,splashScreen:SplashScreen){platform.ready().then(()=>{//Okay,sotheplatformisreadyandourpluginsareavailable.//Hereyoucandoanyhigherlevelnativethingsyoumightneed.//statusBar.styleDefault();//letstatusbaroverlaywebviewthis.statusBar.overlaysWebView(true);this.storage.get('cliente').then((val)=>{if(val!=null||val!=undefined){this.navCtrl.setRoot(RestaurantePage);}else{this.navCtrl.setRoot(LoginPage);}});//setstatusbartowhitethis.statusBar.backgroundColorByHexString('#ffc107');//statusBar.backgroundColorByHexString("ffc107");
  splashScreen.hide();
  });
 }
}

This is the error:

  Uncaught Error: Can not resolve all parameters for MyApp: ([object Object],?, [object Object], [object Object], [object Object]).       at syntaxError ( link )       at CompileMetadataResolver._getDependenciesMetadata ( link )       at CompileMetadataResolver._getTypeMetadata ( link )       at CompileMetadataResolver.getNonNormalizedDirectiveMetadata ( link )       at CompileMetadataResolver._getEntryComponentMetadata ( link )       at link       at Array.forEach (native)       at CompileMetadataResolver._getEntryComponentsFromProvider ( link )       at link       at Array.forEach (native)   syntaxError @ VM21376 main.js: 79180   CompileMetadataResolver._getDependenciesMetadata @ VM21376 main.js: 92517   CompileMetadataResolver._getTypeMetadata @ VM21376 main.js: 92385   CompileMetadataResolver.getNonNormalizedDirectiveMetadata @ VM21376 main.js: 91994   CompileMetadataResolver._getEntryComponentMetadata @ VM21376 main.js: 92638   (anonymous) @ VM21376 main.js: 92624   CompileMetadataResolver._getEntryComponentsFromProvider @ VM21376 main.js: 92623   (anonymous) @ VM21376 main.js: 92587   CompileMetadataResolver._getProvidersMetadata @ VM21376 main.js: 92551   (anonymous) @ VM21376 main.js: 92126   CompileMetadataResolver.getNgModuleMetadata @ VM21376 main.js: 92117   JitCompiler._loadModules @ VM21376 main.js: 103270   JitCompiler. compileModuleAndComponents @ VM21376 main.js: 103229   JitCompiler.compileModuleAsync @ VM21376 main.js: 103191   PlatformRef . bootstrapModuleWithZone @ VM21376 main.js: 5141   PlatformRef .bootstrapModule @ VM21376 main.js: 5127   (anonymous) @ VM21376 main.js: 115016    webpack_require @ VM21376 main.js: 48   (anonymous) @ VM21376 main.js: 140   (anonymous) @ VM21376 main.js: 143

    
asked by anonymous 19.06.2017 / 15:24

2 answers

1

Try removing navController and directly modifying variable rootPage

export class MyApp {

rootPage:any = LoginPage;

  constructor(private storage: Storage, platform: Platform, private statusBar: StatusBar, splashScreen: SplashScreen) {

  platform.ready().then(() => {
  this.statusBar.overlaysWebView(true);
  this.storage.get('cliente').then((val) => {
    if(val != null || val != undefined){
      this.rootPage = RestaurantePage;
    }else{
      this.rootPage = LoginPage;
    }
  });
 }
}
    
19.06.2017 / 15:45
0

If you are browsing through your root component you can not do it that way.

Example:

@Component({
   template: '<ion-nav #myNav [root]="rootPage"></ion-nav>'
})
export class MyApp {
   @ViewChild('myNav') nav: NavController
   public rootPage: any = TabsPage;

   // Wait for the components in MyApp's template to be initialized
   // In this case, we are waiting for the Nav with reference variable of "#myNav"
   ngOnInit() {
      // Let's navigate from TabsPage to Page1
      this.nav.push(Page1);
   }
}

You can see more here where it says: Navigating from the Root component

    
22.06.2017 / 12:42