Skip to content

Instantly share code, notes, and snippets.

@ashconnell
Created April 20, 2015 22:13
Show Gist options
  • Save ashconnell/f7e0d9b91b685df5fc0d to your computer and use it in GitHub Desktop.
Save ashconnell/f7e0d9b91b685df5fc0d to your computer and use it in GitHub Desktop.
Ionic: manipulate history stack
/*
* This example shows how to control the history stack.
* Say if we went A->B->C and then when pressing back, you want it to go to A (skip B)
*/
// Reference current history set
var viewHistory = $ionicHistory.viewHistory();
var history = viewHistory.histories[viewHistory.currentView.historyId];
// Remove both B and C
history.stack.splice(1, 2);
// Set the cursor and backview to A+1 (where we are now)
history.cursor = 1;
viewHistory.backView = history.stack[0];
// Trigger back using $ionicHistory. Never use window.history.back() etc
$ionicHistory.goBack();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment