How to remove a page from Ionic 2 / 3 navigation

Asked

Viewed 770 times

4

In a hybrid application with Ionic 3 I have 3 pages that are part of the process of buying a product.

The process is as follows:

  1. The user is in the cart and click on "Choose payment method"
  2. In case he’s logged is redirected to checkout page
  3. If you’re not logged is redirected to authentication page
  4. If it was for authentication and logged in I redirect to checkout

We can imagine a diagram like this:

  1. If you are logged

    [CART] => [CHECKOUT]

  2. If you’re not logged

    [CART] => [AUTHENTICATION] => [CHECKOUT]

The problem is that if I’m on the checkout after having authenticated and go back to the previous page it goes back to the authentication page and I’d like it to skip it and go back to the cart

I tried numerous variations of the code below unsuccessfully:

// Após autenticar com sucesso
this.navCtrl.push("CheckoutPage").then(() => {
    const index = self.navCtrl.getActive().index;
    self.navCtrl.remove(index);
});

How can I remove a page from Ionic 2/3 navigation?

1 answer

1


Try subtracting -1 from the navController

ex:

this.navCtrl.push('CheckoutPage').then(() => {
   const index = self.navCtrl.getActive().index - 1;
   self.navCtrl.remove(index, 1);
});

When you push on CheckoutPage the same is added in the index, then removing 1 (self.navCtrl.getActive().index - 1) you remove the authentication view and not the view CheckoutPage.

Browser other questions tagged

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