【问题标题】:How to remove last page with using $window.history.back()如何使用 $window.history.back() 删除最后一页
【发布时间】:2018-02-23 00:38:11
【问题描述】:

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

  1. 在主页显示项目列表。
  2. 单击一项并移至详细信息页面。
  3. 我想改变一些东西,所以点击编辑按钮并移动到编辑页面。
  4. 编辑一些内容并单击确认按钮完成编辑。
  5. 点击按钮时,执行$state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'});
  6. 然后转到详细信息页面。

通过这些,位置历史有连续的详细页面。

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

而且我认为使用$window.histroy.back(); 比使用更合适

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

删除历史记录。

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

.

.

.

我添加了我的 Paint 文件以便于理解我想要什么。 :)

1。

2。

3。

【问题讨论】:

  • 看看这个:stackoverflow.com/questions/28743405/… 如果有帮助的话。
  • @AvneshShakya 我已经看过那篇文章,但不知道如何在我的代码中调整它。我使用的是ui-router,所以$state.go是移动url的主要功能。
  • @AvneshShakya 并使用与 $state.go('root.detail', {cat_id : $scope.cat_id}, {location: 'replace'}); 相同的替换执行。
  • 你可以试试$state.transitionTo。看到这个:github.com/angular-ui/ui-router/issues/860 看到这个:stackoverflow.com/questions/21105528/…
  • @AvneshShakya 是$state.transitionTo 更具体地使用$state.go 吗?我也试过了,结果是一样的。

标签: angularjs angular-ui-router history


【解决方案1】:

这就是我的解决方法

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

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

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

【讨论】:

    猜你喜欢
    • 2014-12-17
    • 2019-10-08
    • 1970-01-01
    • 2021-07-19
    • 2013-07-16
    • 2016-11-15
    • 1970-01-01
    • 2013-12-19
    • 2012-06-03
    相关资源
    最近更新 更多