0

Estou utilizando este comando this.navCtrl.push('HomePage'); para navegar entre as paginas no ionic 3 porém preciso fazer com que ele não apareça assim o:

inserir a descrição da imagem aqui

Não posso da a chance do cara voltar para próxima tela.

Na verdade o que preciso é um if() se o usuário ja estiver logado a rootPage é uma se não é outra.

Como fazer isto ?

Tentei fazer assim:

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();
  });
 }
}

Este é o erro:

Uncaught Error: Can't resolve all parameters for MyApp: ([object Object], ?, [object Object], [object Object], [object Object]). at syntaxError (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

1

2 Respostas 2

1

Tente remover o navController e modificar diretamente a variável 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;
    }
  });
 }
}
4
  • Mesmo erro ainda Commented 19/06/2017 às 14:03
  • Você removeu o public navCtrl: NavController? Commented 19/06/2017 às 14:08
  • Não deixa testar Commented 19/06/2017 às 14:24
  • continua Uncaught Error: Can't resolve all parameters for MyApp: Commented 19/06/2017 às 14:26
0

Se estas a navegar através do teu root component não podes fazer dessa forma.

Exemplo:

@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);
   }
}

Podes ver mais aqui onde diz: Navigating from the Root component

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .