ui-router changing the previous state

abkds

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

AdityaParab

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ui-router - stop changing state on resolve

From Dev

Using ui-router to simply launch a function without changing state

From Dev

URL is not changing even after the state is changed . `ui-router`

From Dev

UI-router change state without changing url

From Dev

AngularJS: Controllers registering multiple times when changing state with UI Router

From Dev

Using ui-router to simply launch a function without changing state

From Dev

Preventing ui-router state controller reload after changing state with params

From Dev

ui.router changing state, but ui-view doesn't display anything?

From Dev

UI router state not loading

From Dev

Anguarjs: ui-router modal window to return to previous state, without re-entering it

From Dev

AngularJS ui-router $state.go('^') only changing URL in address bar, but not loading controller

From Dev

Angular ui-router: Can you change state without changing URL?

From Dev

Changing the default behavior of $state.go() in ui.router to reload by default

From Dev

AngularJS ui-router $state.go('^') only changing URL in address bar, but not loading controller

From Dev

UI Router changing URL but not page

From Dev

jquery toggle state not changing .text to previous value

From Dev

Angular UI Router state navigation

From Dev

Angular - UI Router - state reentrance

From Dev

UI Router - Check if a state exists

From Dev

UI Router - Check if a state exists

From Dev

Get previous location in Angularjs ui-router

From Dev

Dynamically changing View in AngularJS UI-Router

From Dev

Changing Rails Pages to UI.router pages

From Dev

Buttons dissapearing after changing State UI Routing

From Dev

UI Router State Change Tracking in Google Analytics

From Dev

ui-router default child state not working

From Dev

Cannot get ui-router state params

From Dev

ui-router modal window with parent state

From Dev

AngularJs ui-router $location or $state?

Related Related

  1. 1

    ui-router - stop changing state on resolve

  2. 2

    Using ui-router to simply launch a function without changing state

  3. 3

    URL is not changing even after the state is changed . `ui-router`

  4. 4

    UI-router change state without changing url

  5. 5

    AngularJS: Controllers registering multiple times when changing state with UI Router

  6. 6

    Using ui-router to simply launch a function without changing state

  7. 7

    Preventing ui-router state controller reload after changing state with params

  8. 8

    ui.router changing state, but ui-view doesn't display anything?

  9. 9

    UI router state not loading

  10. 10

    Anguarjs: ui-router modal window to return to previous state, without re-entering it

  11. 11

    AngularJS ui-router $state.go('^') only changing URL in address bar, but not loading controller

  12. 12

    Angular ui-router: Can you change state without changing URL?

  13. 13

    Changing the default behavior of $state.go() in ui.router to reload by default

  14. 14

    AngularJS ui-router $state.go('^') only changing URL in address bar, but not loading controller

  15. 15

    UI Router changing URL but not page

  16. 16

    jquery toggle state not changing .text to previous value

  17. 17

    Angular UI Router state navigation

  18. 18

    Angular - UI Router - state reentrance

  19. 19

    UI Router - Check if a state exists

  20. 20

    UI Router - Check if a state exists

  21. 21

    Get previous location in Angularjs ui-router

  22. 22

    Dynamically changing View in AngularJS UI-Router

  23. 23

    Changing Rails Pages to UI.router pages

  24. 24

    Buttons dissapearing after changing State UI Routing

  25. 25

    UI Router State Change Tracking in Google Analytics

  26. 26

    ui-router default child state not working

  27. 27

    Cannot get ui-router state params

  28. 28

    ui-router modal window with parent state

  29. 29

    AngularJs ui-router $location or $state?

HotTag

Archive