ionic-team / ionic-v1

The repo for Ionic 1.x. For the latest version of Ionic, please see https://github.com/ionic-team/ionic
Other
192 stars 187 forks source link

Removing multiple views from history stack #283

Open yazantahhan opened 7 years ago

yazantahhan commented 7 years ago

Short description of the problem:

I'm trying to remove multiple views before transition to another state using $ionicHistory.removeBackView(). It gives me the following error:

TypeError: Cannot set property 'backViewId' of undefined

What behavior are you expecting?

It should remove multiple views when invoking $ionicHistory.removeBackView() multiple times.

Steps to reproduce:

  1. Open plunker below.
  2. Click on the side menu items until you click on "Remove Back View Two times".
  3. Check the console.

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

What I found is that currentHistory.currentCursor should be currentHistory.cursor instead to change the cursor as used in line 620. As the currentHistory.currentCursor is not found in any other place. Please correct me if I'm wrong.

Which Ionic Version? 2.1.18.

Plunker that shows an example of your issue

http://plnkr.co/edit/A0k6nlu16tYbWD5tYexa?p=preview

Run ionic info from terminal/cmd prompt: (paste output below)

Your system information:

ordova CLI: 6.5.0 Ionic CLI Version: 2.1.18 Ionic App Lib Version: 2.1.9 ios-deploy version: Not installed ios-sim version: Not installed OS: Windows 7 Node Version: v6.10.3 Xcode version: Not installed

spixy commented 6 years ago

One year later and I have the same problem 😞

yazantahhan commented 6 years ago

I did a workaround regarding this.

Instead of removing the backviews, we can go back to the specified view by the goBack(backCount) function with the number of views to go back.

In order to make this workaround work, we need to specify which state we want to go back to. The following function will get the stateName, check how many views are in front of it, and then go back to it.

function goBackToMatchedView(stateName) { var backCount = 0; var historyKey = this.$ionicHistory.currentView().historyId; var views = this.$ionicHistory.viewHistory().histories[historyKey].stack; var index = views.length - 1; while (!views[index].stateName.includes(stateName)) { index--; backCount-- } $ionicHistory.goBack(backCount); }