0

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

7
  • Simple solution would be to have only 2 states, X and Z. When you select some details on X page and go to Y, instead of going to Y with ui.router, hide the current div and show the div that has contents of the Y. Then upon selecting further details, go to Z using ui.router.. Commented Apr 4, 2016 at 5:53
  • @AdityaParab, I need a different page Y Commented Apr 4, 2016 at 5:54
  • Do you mean page as in it has to have a route? Commented Apr 4, 2016 at 5:55
  • yes every page has a different route Commented Apr 4, 2016 at 5:58
  • Take a look into this post. Commented Apr 4, 2016 at 6:20

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

do like this give your state in $state.go like.. : $state.go('y')

1 Comment

That's the point right, how to do that on the browser back button

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.