-
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
event.preventDefault() on $stateChangeStart
together with '$urlRouterProvider.when("/", "/home")' causes infinite digest loop
#2098
Comments
I seem to have found possible solution to the problem, please validate:
|
I get the same error. Please check this plunk. |
Yes, your problem comes from the same cause as mine, just that you use |
+1...We hit this issue too---solved with (original solution by @frankwallis on issue #600 ): $urlRouterProvider.otherwise( function($injector) { |
@megabyzus wowow.. It is also working for me $urlRouterProvider.otherwise('/dashboard'); to $urlRouterProvider.otherwise( function($injector) {
var $state = $injector.get("$state");
$state.go('app.dashboard');
}); |
So, to fix for $urlRouterProvider.when: Change this:
To this:
|
duplicate of #2238 |
As mentioned here, #1022 (comment), this is was not fixed on 0.2.16. So anyone still experiencing this, should apply this workaround. |
@nfantoneif would you mind posting a plunker showing your scenario? I'd be happy to reopen this if I can be shown that it's still a problem. |
@christopherthielen Well... this is happening in a rather large project. Putting together a plunkr won't be as easy as copy and pasting. Let me see what I can do. But the symptoms are exactly the same as everyone else have described. And the solution was also the same fix. Also, it seems I'm not the only one experiencing this after the alleged fix. |
… has started Closes angular-ui#2238 Closes angular-ui#2229 Closes angular-ui#2185 Closes angular-ui#2236 Closes angular-ui#2098 Closes angular-ui#600
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 didn't added /* @ngInject */ in myfile.js since I'm using typescript. Check the error parameter value to identify the exact cause.
|
I want to redirect user to default
mydomain.com/home
url when she hitsmydomain.com
. So I have the following in my config:Also, in my module's run function I subscribe to the
$stateChangeStart
event and if a user hasn't yet been resolved from the server I prevent the event until the user is resolved:The problem is that
event.preventDefault();
used in such a way causes infinite digest loop. Unfortunately, I can't reproduce this issue inside plunker probably because of some URL inconsistencies but it's reproducable inside simple.html
file - here is the gist with this file's content.I've also done a bit of debugging myself. When
$stateChangeStart
is fired, the router is transitioning to thehome
state with the urlmydomain.com/home
. This url is already set in a browser by angular. Then if transition is prevented, ui-router sets the url back to the original "/" here:Then angular's this
$rootScope.$watch(function $locationWatch() {
watcher is fired which checks for location changevar urlOrStateChanged = oldUrl !== newUrl
and finds the change, because URLs don't match -oldUrl
isdomain.com/home
andnewUrl
isdomain.com/
(set by router). Since there's a change, angular fires$locationChangeSuccess
event, which is picked up byui-router
. In turn,ui-router
finds this rule.when("/", "/home")
and changes state tohome
, but the event is prevented again and so the closed-loop is continuing with angular's watcher's being fired again.The text was updated successfully, but these errors were encountered: