Push screens Ionic 3

Asked

Viewed 646 times

0

I’m using this command this.navCtrl.push('HomePage'); to navigate between pages on ionic 3 but I need to make sure he doesn’t show up like this:

inserir a descrição da imagem aqui

I can’t give the guy a chance to get back to the next screen.

Actually what I need is a if() if the user is already logged in to rootPage is one if it is not another.

How to do this ?

I tried to do so:

export class MyApp {

rootPage:any = LoginPage;

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

  platform.ready().then(() => {
  // Okay, so the platform is ready and our plugins are available.
  // Here you can do any higher level native things you might need.
  // statusBar.styleDefault();
  // let status bar overlay webview
  this.statusBar.overlaysWebView(true);
  this.storage.get('cliente').then((val) => {
    if(val != null || val != undefined){
      this.navCtrl.setRoot(RestaurantePage);
    }else{
      this.navCtrl.setRoot(LoginPage);
    }
  });

  // set status bar to white
  this.statusBar.backgroundColorByHexString('#ffc107');
  //statusBar.backgroundColorByHexString("ffc107");
  splashScreen.hide();
  });
 }
}

This is the mistake:

Uncaught Error: Can’t resolve all Parameters for Myapp: ([Object Object], ?, [Object Object], [Object Object], [Object Object]). syntat axError (http://localhost:8100/build/main.js:79180:34) At compilemetadataresolver. _getDependenciesMetadata (http://localhost:8100/build/main.js:92517:35) At compilemetadataresolver. _getTypeMetadata (http://localhost:8100/build/main.js:92385:26) At Compilemetadataresolver.getNonNormalizedDirectiveMetadata (http://localhost:8100/build/main.js:91994:24) At compilemetadataresolver. _getEntryComponentMetadata (http://localhost:8100/build/main.js:92638:45) at http://localhost:8100/build/main.js:92624:48 at Array.foreach (Native) At compilemetadataresolver. _getEntryComponentsFromProvider (http://localhost:8100/build/main.js:92623:30) at http://localhost:8100/build/main.js:92587:83 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

  • You installed the plugin and followed the steps it says here https://ionicframework.com/docs/storage/ ?

2 answers

1


Try to remove the navController and directly modify the 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;
    }
  });
 }
}
  • Same mistake yet

  • You removed the public navCtrl: NavController?

  • Does not let test

  • continue Uncaught Error: Can’t resolve all Parameters for Myapp:

0

If you are browsing through your root Component you cannot do so.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.