我的问题是 ui-router $stateChangeError
不是由“404”无效状态触发的。
我确定我的 $stateChangeSucess
正确触发:
$rootScope.$on('$stateChangeSuccess',
function(event, toState, toParams, fromState, fromParams)
当我故意使状态无效时:
<ui-view>
<a ui-sref="foo" style="cursor: pointer;">Foo is not a state</a>
</ui-view>
$stateChangeError
事件没有被触发,我知道我有正确的签名
angular
.module('blocks.router')
.run(['$rootScope', function($rootScope) {
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) {
console.log('$stateChangeError fired!');
});
}]);
我将我的函数添加到 $stateChangeError
,同时我添加了我的工作 $stateChangeSuccess
。
对我可能做错的地方有什么建议吗?
最佳答案
Angular-ui-router 有 $stateNotFound
对于这种情况
关于javascript - angular-ui/ui-router $stateChangeError 从不为不存在的状态触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39069378/