有没有办法创建一个可关闭的按钮,该按钮转到 404 页面被阻​​止的页面?

Is there a way to create a dismissible button that goes to the page where the 404 page was blocking?

在我使用 ui-router 的项目中,我有一个 404 页面,只要某个组件不存在(否则)就会出现。因此,不是显示损坏的 JSON,而是触发 404 页面。有没有办法在我的 404 页面上创建一个按钮,单击该按钮会将用户带到损坏的 JSON 页面?

您可以使用 $rootScope , $stateChangeStart

捕捉参数和状态
app.run(function($rootScope, SpinnerService) {
  $rootScope.$on('$stateChangeStart', function(evt, toState, toParams, fromState, fromParams) {
    console.log("$stateChangeStart " + fromState.name + JSON.stringify(fromParams) + " -> " + toState.name + JSON.stringify(toParams));
    if(toState.name === 'errorPage'){
        toParams.latestState = fromState;
    }

  });
})

创建一个包含您的错误页面的状态。并添加使用最新参数和最新状态的状态操作。

$stateProvider.state('errorPage', {
  templateProvider: function ($timeout, $stateParams) {
    return $timeout(function () {
      return '<button ui-sref="'+$stateParams.latestState+'"></button>'
    }, 100);
  }
})

您可以使用模板、控制器、templateUrl、controllerProvider 或将最新变量存储在 $rootScope 中。

有很多方法可以做到。我想仔细阅读这篇文章https://github.com/angular-ui/ui-router/wiki