Prevent <ion-view> from adding to history back stack (historyPush:false feature)

Continuing the discussion from Please help test: Angular 1.3, improved transitions, cached views, etc:

Any update on this feature request? The ability to manipulate the back stack – specifically, preventing a particular page from entering the history – is quite important. The JavaScript location.replace() and ui-router $state.go(..., ..., {location: "replace"}) analogs have existed for ages.

1 Like

agree on need for this feature, banging head on wall right now because i can’t add to the ionic back history…

almost got this to work, but would be really cool if someone who really knows the history stuff could get it to really work… I added this to $ionicHistory:

pushHistory: function(scope){
  var currentView = viewHistory.currentView,
  par = getParentHistoryObj(scope),
  currentStateId = getCurrentStateId()
  
  hist = getHistory(par.scope)
  viewId = ionic.Utils.nextUid();
  view = this.createView({
    viewId: viewId,
    index: hist.stack.length,
    historyId: hist.historyId,
    backViewId: (currentView && currentView.viewId ? currentView.viewId : null),
    forwardViewId: null,
    stateId: currentStateId,
    stateName: this.currentStateName(),
    stateParams: getCurrentStateParams(),
    url: $location.url()
  });
  viewHistory.views[viewId] = view

  // add the new view to this history's stack
  hist.stack.push(viewHistory.views[viewId]);
  viewHistory.backView = viewHistory.currentView
  viewHistory.currentView = view
},

then i call it whenever i switch states without notify, so that it picks up the state

almost works, browser back seems to behave better, back button still finicky

In case this helps anyone, I have a snippet that manipulates the history. My case is where there from the 2nd screen in the app, there is 3 more screens to select something, and if you complete the action on the last screen then I want to pop those 3 screens off the stack.

var viewHistory = $ionicHistory.viewHistory()
// pop off the photo selection screens and set the back view to the profile edit page
var history = viewHistory.histories[viewHistory.currentView.historyId]
history.stack.splice(2, 3)
history.cursor = 1
viewHistory.backView = history.stack[1]
$ionicHistory.goBack()
1 Like