我的問題是,UI路由器$stateChangeError
不是由「404」 invaild狀態觸發的狀態。
我確實知道我對$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!');
});
}]);
而且我加m y功能在同一時間我加我的工作$stateChangeSuccess
。
什麼,我可能是做錯了什麼建議?
你執行'$ urlRouterProvider.otherwise()'?如果是這樣,這就是爲什麼無效狀態不會觸發錯誤 – Phil
不,我目前沒有實現$ urlRouterProvider.otherwise() –
@Phil添加$ urlRouterProvider.otherwise(「/」)沒有觸發錯誤 –