Reputation: 1794
The app has pages, X
, Y
and Z
. So the routing should be as follows I go into page X
and then select some details and then go to page Y
and then select some more details and then go to Z
. So I want that after going to Z
page once I click window back button it should go to page X
and not page Y
. While going from Y
to Z
, I also tried adding { location: 'replace' }
in $state.go
but it doesn't work. Any ideas on how to achieve that ?
Thanks
Upvotes: 0
Views: 105
Reputation: 7100
Every time you change a state, Angular will trigger an event called $stateChangeStart
, you can use that to your advantage.
In your app.run
, do
app.run(function($rootScope,$state){
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
//Check if you're going from Z to Y
if(fromState.name === 'Z' && toState.name === 'Y'){
// if so, first stop the default behavior
event.preventDefault();
// then navigate to X
$state.go('X');
}
});
});
The browser back button essentially triggers the same event so your problem will be solved with this.
Upvotes: 3
Reputation: 746
do like this
give your state in $state.go like.. :
$state.go('y')
Upvotes: 0