-
Notifications
You must be signed in to change notification settings - Fork 3k
Infinite loop when redirecting to state from $stateChangeError handler #898
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
Comments
Would you be able to create a plunkr? |
Yes, sure http://plnkr.co/edit/UkzlV6vTexZ36XwP0Lnm?p=preview. But I don't know the way to tell Plunker to go to some non-existent url so this plunk doesn't demonstrate problem, all works as expected. |
Wouldn't this plunkr be your proper test case? http://plnkr.co/edit/qJioRE9UGTNX8WV4KneM?p=preview Seems to be working fine to me. |
No, as I mentioned before, if we successfully entered some state all subsequent redirects working fine. But if you run this example locally and point browser directly to localhost/#/abc it would be endlessly cycling. |
Any update on this? I'm having the same issue. |
I ended up just setting window.location.pathname rather than using $location.path() or $state.go(). |
I'm using v1.2.16, is there a resolution for this issue? I get an infinite loop when I try to implement authentication in the run event. I tried using state, location and windows.location all for the same result. |
Your resolve functions should be returning a promise (or an object you want to inject). See docs: https://github.com/angular-ui/ui-router/wiki#resolve So, instead of returning
and
|
I believe what what @mattcasey meant is that you should return Also, returning Here are the docs for the $q service |
@mattcasey the return value of registering a timeout function is a promise, which will be resolved when the timeout is reached and the timeout function is executed. |
You can fix this by calling event.preventDefault() in the handler for $stateChangeError
|
@evandrewry event.preventDefault() worked perfect thanks. |
@evandrewry : event.preventDefault() also worked for me...thank you so much for posting this! I was banging my head for hours until I came across this post. |
Seems @evandrewry has the fix |
Here is a minimal example I made to reproduce my issue:
The problem is when going to any non-existent url such as '/abc' for example - app falls to infinite 'location change' loop. Url should be pasted directly to browser address string because if previously we entered some valid state all subsequent redirects would work as expected.
By 'location change' loop I mean following:
The text was updated successfully, but these errors were encountered: