【问题标题】:Ionic pop page not working离子弹出页面不起作用
【发布时间】:2017-11-20 08:50:25
【问题描述】:

我对 Ionic 很陌生,我很难回到上一页。 错误未捕获(承诺):导航堆栈至少需要一个根。 但是在 login() 中,我将 TabsPage 推到根 (LoginPage) 上方。 使用 pop() 我想回到 LoginPage。

如果你能帮忙,我会很高兴。

这是我的代码:

myApp.ts:

export class MyApp {
  rootPage:any = 'LoginPage';

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
    });
  }
}

login.ts:

public login() { 
    this.showLoading()
    this.auth.login(this.registerCredentials).subscribe(allowed => {
      if (allowed) {        
        this.nav.push(TabsPage);
      } else {
        this.showError("Email ou mot de passe incorrect");
      }
    },
      error => {
        this.showError(error);
      });
  }

标签:

export class TabsPage {

  tab1Root = OrdersPage;
  tab2Root = AboutPage;
  tab3Root = ProfilePage;

  /**
   * @constructor
   */
  constructor(private navCtrl: NavController) {}
}

profile.ts:

    public logout(){
      this.auth.logout().subscribe(logedout => {
          if(logedout){
              this.navCtrl.pop();
          }
      });
  }

谢谢。

【问题讨论】:

  • 你说的是TabsPage,但我没有看到它的代码。
  • @Protectator 感谢您的回答。我更新了我的问题
  • 我看到tab3Root = ProfilePage;。这是否意味着您将根设置为 Profile ?如果是,那么这就是您无法使用pop 返回的原因:配置文件现在是根。

标签: angular typescript ionic2


【解决方案1】:

问题是您正试图从标签根页面弹出。在 Ionic Tabs 中,每个选项卡都是其自己的导航堆栈的根。 您需要使用应用程序 NavController 将LoginPage 设置为 root

在 profile.ts 中,

 import { App } from ionic-angular;


constructor(private app:App){}

public logout(){
  this.auth.logout().subscribe(logedout => {
      if(logedout){
          this.app.getRootNav().setRoot(LoginPage);
      }
  });
}

ALSO,您需要从 LoginPage 将 TabsPage 设置为 root 以避免用户按回并返回到 Loginpage。

 if (allowed) {        
    this.nav.setRoot(TabsPage);//here
  } else {
    this.showError("Email ou mot de passe incorrect");
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    • 1970-01-01
    相关资源
    最近更新 更多