Assume that we have a logic like this:
- From state A, change to state B.
- Whenever we arrive to state B, the app always redirect us to state C by calling
$state.go(stateC)
- Now we are in state C
My question is how to go back to state A from state C (given the fact that state A can be any state we don't know at run-time, meaning user can access state B from any other states)
Use the
location
option with value "replace"...See https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_go
You could keep track of visited states in a service and then just call $state.go on the previous state.
You can watch the state changes like so:
How to $watch state change of $stateProvider in AngularJS?