New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirecting on rejected resolve #3331
Comments
You could set this up in your app's run block:
The reject result of the resolve should be passed to the error handler. |
I want to avoid having a global place with if statements. I would like to stay in my state definition. |
You raise a really good point. Resolves are not considered to be "transition hooks" so they cannot explicitly redirect the transition. The reason your other resolves are still processing is likely because you need to return the rejection from the failed resolve. Something like this: .state('foo', {
resolve: {
fails: ($q, $http, $state) =>
$http.get('/404').catch(err => $state.go('recover') && $q.reject(err))
}
}); That should cause the resolve to be rejected (erroring the first transition). Then the second transition (state.go) can proceed |
Thanks, I can try that. But do you feel it as a woraround or something that integrates well with the framework? |
I feel it's a workaround. I think you've raised a good point about a possible enhancement to the framework. |
The workaround worked well. But note that I had to "return" $q.reject(err) to ensure that the rejection is taken into account so that the other resolves are not attempted. |
Revisiting my code and I had a link to this thread in my comments. |
This issue has been automatically marked as stale because it has not had This does not mean that the issue is invalid. Valid issues Thank you for your contributions. |
Hi,
Using ui-router 1.0rc1, I can't find a way, in my state declaration (component-routed), to redirect to another state when a resolve is rejected (my server sends back a 400 status code when a resource can't be found). Is a hook necessary? I hope there is a solution that can be local to each state declaration instead of in a global hook...
I don't think calling $state.go() in a rejection handler inside my resolve function is the thing to do. It seems to work but I noticed that other resolves are called (and one of them depends on the rejected one).
Thanks
The text was updated successfully, but these errors were encountered: