mkkekkonen
mkkekkonen

Reputation: 1774

Ionic 3 NavController refuses to navigate after logout and root page change

I have a weird problem with my Ionic app, I have two different logical navigation stacks, first for login, second for using the actual app after login. On login and logout, the root page is changed and the eventually resulting navigation stack is changed.

navigation hierarchy

The first time I log in, everything works perfectly. However, when I log out from HomePage and switch again to LoginPage, I cannot access LocalLoginPage via its button any more. The click event is registered, I've verified that, but this.navCtrl.push(LocalLoginPage) does nothing.

Relevant LoginPage HTML:

<ion-content padding>

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

</ion-content>

Relevant LoginPage code:

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

Logout button (in HomePage) code:

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

Does anyone have an idea why this happens?

Upvotes: 1

Views: 1498

Answers (1)

Sampath
Sampath

Reputation: 65870

You can try without this.navCtrl.popToRoot();.

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

Upvotes: 1

Related Questions