在我的AngularJS应用程序,我想捕获错误,并且用户发送到404的状态,像这样:AngularJS UI路由器的状态,但使用不同的URL
$rootScope.$on('$stateNotFound', function(event, unfoundState, fromState, fromParams){
//console.log(unfoundState.to);
//console.log(unfoundState.toParams);
//console.log(unfoundState.options);
$state.go('404');
});
这是当用户点击一个坏链路(例如没有状态下,与状态,但没有任何内容那些由否则方法处理)在该应用中,等
的代码加载404状态罚款:
.state('404',
{
views: {
'body': {
templateUrl: 'partials/404.html',
}
}
});
但我想要做的是将URL更改为他们尝试访问的状态,所以基本上加载404状态,但使用不正确的URL(因为404将在服务器环境中工作)。
我已经研究过这样做的:
history.replaceState(null, null, unfoundState.to);
$state.go('404');
但是,这会导致应用程序的主要错误,并改变URL,但不是国家!
我该怎么做?
我还没有尝试过。我不确定'$ state.transitionTo('404',{},{location:false});'是否有效。 – 2014-10-06 14:29:16