首页 文章

Ionic 3 NavController 在注销和根页面更改后拒绝导航

提问于
浏览
1

我的 Ionic 应用程序有一个奇怪的问题,我有两个不同的逻辑导航堆栈,第一个用于登录,第二个用于登录后使用实际应用程序。在登录和注销时,将更改根页面并更改最终生成的导航堆栈。

导航层次结构

我第一次登录时,一切都很完美。但是,当我从 HomePage 注销并再次切换到 LoginPage 时,我无法再通过其按钮访问 LocalLoginPage。 click 事件已注册,我已经验证过,但是this.navCtrl.push(LocalLoginPage)什么也没做。

相关的 LoginPage HTML:

<ion-content padding>

  <button ion-button full (click)="localLogin()">Local login</button>
  <hr/>

</ion-content>

相关的 LoginPage 代码:

localLogin() {
  try {
    this.navCtrl.push(LocalLoginPage);
    console.dir(this.navCtrl.getViews()); // this displays only LoginPage when the error occurs
  } catch(e) {
    window.alert(Util.formatError("localLogin error", e));
  }
}

注销按钮(在 HomePage 中)代码:

@Component({
  selector: 'logout-button',
  templateUrl: 'logout-button.html'
})
export class LogoutButtonComponent {

  constructor(public navCtrl: NavController, public oauthService: OAuthService,
      public localLogin: LocalLoginProvider) {
  }

  logout() {
    this.oauthService.logOut();
    this.localLogin.user = null;
    this.navCtrl.setRoot(LoginPage);
    this.navCtrl.popToRoot();
  }
}

有谁知道为什么会这样?

1 回答

  • 1

    你可以试试没有this.navCtrl.popToRoot();

    logout() {
        this.oauthService.logOut();
        this.localLogin.user = null;
        this.navCtrl.setRoot(LoginPage);    
      }
    

相关问题