How to remove a page from Ionic navigation 2/3

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:

  • The user is in the cart and clicks the "Choose payment method" button
  • If he is logged in is redirected to checkout page
  • If not logged in is redirected to authentication page
  • If it was for authentication and logged in I redirected to the checkout
  • We can imagine a diagram like this:

  • If you are logged in

    [CART] = > [CHECKOUT]

  • If you are not logged in

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

  • The problem is that if I am at the checkout after I have authenticated and go back to the previous page it returns to the authentication page and I would like it to skip it and return to the cart

    I tried numerous variations of the code below without success:

    // 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?

        
    asked by anonymous 06.11.2017 / 21:32

    1 answer

    1

    Try subtracting -1 from the index of navController

    ex:

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

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

        
    10.11.2017 / 17:01