不,它不是重复的。我曾经使用搜索,甚至看过这个Go to the error state and keep the URL to the state generating the error,但都没有关系。
在UI-Router 1.0+中,不再有事件,它们被Transition Hooks替换。当我使用onError()
Transition的钩子时,我发现的所有问题都与纯状态配置有关。
这就是我所拥有的:
$transitions.onError({to: 'parent.**'}, transition => {
// go to error, don't change location
// but at this point, transition to invalid state did not
// happen, so the URL represents last valid 'parent' state
$state.go('error', {}, {location: false});
let badStateUrl = $state.href(transition.to().name, transition.params()).replace(/^#/, '');
// And this actually triggers infinite loop, as URL change
// triggers state change life cycle, which I need to avoid
$urlService.url(badStateUrl , true);
// Tried $location.path() - same thing, goes to infinite loop
});
这个想法是,如果用户试图从有效状态导航到无效状态(例如缺少资源),我想将该无效URL保留在地址栏中,以便在视觉上与错误同步。否则,如果找不到资源,则会将用户重定向到错误状态,但URL看起来有效,因为该URL才起作用。
谢谢