如何使用$ window.history.back()删除最后一页

时间:2017-09-14 06:36:56

标签: angularjs angular-ui-router history

在我的代码中,逻辑执行如下所示。

  1. 在主页中显示项目列表。
  2. 单击一个项目并移至详细信息页面。
  3. 我想改变一些东西,所以点击编辑按钮然后移动到编辑页面。
  4. 编辑一些并完成编辑,然后单击确认按钮。
  5. 点击按钮后,执行$state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'});
  6. 然后转到详细页面。
  7. 通过这些,位置记录具有连续的详细页面。

    我知道我们无法处理历史。

    我认为使用$window.histroy.back();更合适,而不是使用

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

    删除历史记录。

    有人有想法解决这个问题吗?

    我添加了我的Paint文件,以便于理解我想要的内容。 :)

    1。 enter image description here

    2。 enter image description here

    3。 enter image description here

1 个答案:

答案 0 :(得分:0)

这就是我的解决方法

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

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

将此代码放在详细信息页面控制器中,并将$ location添加为依赖项。...