Remove a view from the back history - Ionic2

前端 未结 3 1510
南旧
南旧 2021-02-02 16:01

Anyone knows how to remove a view from the back history (or navigation stack) in ionic2?

In Ionic 1 I solved this with

this.$ionicHistory.nextViewOptions         


        
相关标签:
3条回答
  • 2021-02-02 16:32

    To remove one backview you need to use startIndex and count of pages to remove from stack.

        this.navCtrl.push(NextPage)
        .then(() => {
          const startIndex = this.navCtrl.getActive().index - 1;
          this.navCtrl.remove(startIndex, 1);
        });
    

    See this document for more options like removeView(viewController): https://ionicframework.com/docs/v2/api/navigation/NavController/#remove

    0 讨论(0)
  • 2021-02-02 16:38

    obrejacatalin on the https://forum.ionicframework.com/t/solved-disable-back-in-ionic2/57457 found the solution

    this.nav.push(TabsPage).then(() => {
      const index = this.nav.getActive().index;
      this.nav.remove(0, index);
    });
    

    so I guess it's important to push the next page first, wait for the promise answer and then remove the current view

    0 讨论(0)
  • 2021-02-02 16:47

    I got the same issue with Ionic 3.
    So, only two steps to reset history:

    // ...
    constructor(public navCtrl: NavController) { }
    // ...
    this.navCtrl.setRoot(NewPageWithoutPrev);
    this.navCtrl.popToRoot();
    // ...
    

    Links:
    https://ionicframework.com/docs/api/navigation/NavController/#setRoot
    https://ionicframework.com/docs/api/navigation/NavController/#popToRoot

    0 讨论(0)
提交回复
热议问题