2

In my code, logics are executed like belows.

  1. Showing items list in main page.
  2. Click one item and move to detail page.
  3. I wanna change something, so click edit button and move to edit page.
  4. Edit some and finish editing with click the confirm button.
  5. When click the button, execute $state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'});.
  6. Then move to detail page.

Through these, location history has successive detail page.

I know that we cannot handle history.

And I think using $window.histroy.back(); is more appropriate instead of using

$state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'});

to remove history.

Anyone have idea to solve this?

.

.

.

I add my Paint files to make easy understanding what I want. :)

1. enter image description here

2. enter image description here

3. enter image description here

Canet Robern
  • 1,049
  • 2
  • 11
  • 28
  • 1
    See this: https://stackoverflow.com/questions/28743405/angularjs-how-to-remove-current-view-url-from-window-history If it helps. – Avnesh Shakya Sep 14 '17 at 06:49
  • @AvneshShakya I already see that post, but don't know how to adapt that in my code. I'm using ui-router, so `$state.go` is main function to move url. – Canet Robern Sep 14 '17 at 06:59
  • @AvneshShakya and using replace executed same as `$state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'});`. – Canet Robern Sep 14 '17 at 07:02
  • 1
    You can try `$state.transitionTo` for this. See this: https://github.com/angular-ui/ui-router/issues/860 and see this: https://stackoverflow.com/questions/21105528/difference-between-state-transitionto-and-state-go-in-angular-ui-router – Avnesh Shakya Sep 14 '17 at 07:30
  • @AvneshShakya Is `$state.transitionTo` for using `$state.go` more specifically? I tried it also but, result is same. – Canet Robern Sep 14 '17 at 09:06

1 Answers1

0

This is how I solved mine

    $scope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){  

         if(fromState.name == 'root.detail' && toState.name == "root.login"){
                 $location.path('/detailPagePath').replace();   
         };     
    });

Put this code in the detail page controller and add $location as a dependency....

David Addoteye
  • 1,587
  • 1
  • 19
  • 31