-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Redirect loop on state with errored resolve #1022
Comments
Same issue on my project. |
I got a similar issue when using ui-router on an angular app when another angular app existed on the page that did not use ui-router. My solution was to change my $urlRouterProvider.otherwise('/') to a function that just directly $state.go'ed to the intended default state. I know this is only tangentially related but it's definitely a hard problem to solve/lookup so hopefully I've helped someone here and we can figure out what's going on with the overall issue. |
My solution so far has been to drop support for optional trailing slashes. Our users should never need to type a URL manually so it's a niggle only for devs who keep getting urls wrong. I will be trying @mfunkie's suggestion though. |
My solution actually proved itself to not work downstream. My real issue was two separate Angular apps with a different idea of what $location.absUrl() should be. My hack was to put an event on $locationChangeStart in the app that didn't use routing. If there were more than 4 locationChangeStarts in a second, I prevented the default actions from occurring in the event handler and that solved my issue. |
@mfunkie Thanks you so much for posting. I was looking for a solution for a whole day, and your use case is the same as mine. |
I wish I knew of a better way to fix it though. Right now I have a routing integration module I have to require on any angular app that coexists on a page with preexisting routing. It seems like an edge case but it's very real for legacy apps that are migrating to SPA over a long period of time. |
It seems like we have faced to the same issue. UPD.
which did not cause infinite loop. It's useful. But the compilation error is still not reported and it's sad. Test your resolvers before you use them with $state. |
@mfunkie Thank you! Your workaround with observing $locationChangeStart also worked in my project. For me it's still not clear what is actually causing this. |
Hi there, $locationProvider.html5Mode(true); If I remove $locationProvider it is fine but I'd like to keep the html5Mode. For now, I just wrap $urlRouterProvider in a try/catch. It works but I don't like that "work around". Update: |
Thanks @KevinOl Using the $injector worked for me. Seems to have changed/broken in latest release. Worked in 0.2.11, but not in 0.2.13 |
Any update on this issue?? |
Any update .. |
It worked for me too @KevinOl thanks a lot |
Also fixed by using @dmytro-shchurov and @KevinOl solution:
Can anyone explain the cause behind it? Can we expect it to be fixed in a future release? Cheers! |
I use v0.2.13 and I didn't fix this issue by using @dmytro-shchurov and @KevinOl solution , BUT I found a solution at there. I hope it can help you ;) |
I'm getting a similar problem. I have an anchor www.website.com/#something and a route www.website.com/:slug/:param. When I hit the anchor and then I use url-sref or $state.go, I get Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! after that the router call otherwise and redirect me to '/' |
@dmytro-shchurov solution also worked here. Thank you! |
A "throttle" solved it for me. var redirectInProgress = false;
$urlRouterProvider.when(/^([\/])?$/, function ($state, $timeout) {
if (!redirectInProgress) {
redirectInProgress = true;
$timeout(function () {
redirectInProgress = false;
}, 100);
return $state.href(App.ui.states.spacesList);
}
}); |
@dmytro-shchurov your solution fixed my same issue, using angular-ui-router 0.2.15 w/ angular 1.4.4 |
possible duplicate of #2238 ? https://gist.github.com/eddiemonge/f6a58169c2846731a1eb |
I just tried using the following but still get redirected back to the previous state.
|
Try placing a
|
@eddiemonge This is still happening on 0.2.18 using Angular 1.5.2. Above solution fixed it for me. Replacing $urlRouterProvider.otherwise(function($injector) {
var $state = $injector.get('$state');
return $state.go('some.state');
}); prevents infinite looping. Maybe re-open the issue? |
I also just experienced this with ionic. $urlRouterProvider.otherwise(function($injector)... Fixed the issue. Just spent 3 hours trying to figure out why the infinite loop. |
So... It's nearing two years and a half now... @eddiemonge Is this still an ongoing issue? |
I can confirm that this bug still happens. I solved it with this:
I am using Angular 1.6.4 and ui-router 0.4.2 |
I'm also faced the same issue, in my case I have $urlRouterProvider.otherwise("/dashboard") in route and event.preventDefault() in $stateChangeError block. I tried with code mentioned by boonep, that's not solved my case. Problem with my code was I missed /* @ngInject */ in myfile.js. Since I'm using typescript (Don't know exactly, may be build tool require this) I need to use
Check the error parameter value to identify the exact cause.
|
In our code we are using the code in the faq for optional trailing slashes. We also have a number of states loading data using the
resolve
attribute.I observe the following four cases when navigating to states that use
resolve
, both from other states, and when navigated to directly by URL:If we then include the redirection for trailing slashes in the FAQ, and navigate to the same states but without a trailing / then all of these cases other than the bottom right remain the same.
When navigating directly to a state whose resolution fails, we get into a loop where the redirect adds a /, starting a transition to the state, the state then fails during its resolve and redirects back to the address without a /. This loop continues flipping the / back and forth until we receive the following two 'infinite digest' errors.
I am unsure of what the expected behavior here is, though I would assume a digest error is not it. I would probably expect the same behavior as I would see without the / redirect - stay on the original URL, or even the errored state's URL but not complete the transition.
Is there something I should do differently here to avoid this case, or is this a bug?
Plunker example here: http://plnkr.co/edit/28AQYE?p=preview
The text was updated successfully, but these errors were encountered: