-
Notifications
You must be signed in to change notification settings - Fork 3k
Using $urlRouterProvider.when() and $stateChangeSuccess/event.preventDefault() the same time lead to infinite loop #1348
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
I wasted days trying to solve the issues revolves around the changeState... For this issue I figured that if I add this code, it works:
|
@lonormaly Actually I have found a workaround as well: add an $rootScope.$on('$stateChangeStart', function(e, toState, toParams, fromState, fromParams) {
e.preventDefault();
$urlRouter.update(true); // add this!
checkAuthorization().then(function() {
$state.go(toState, toParams, {notify: false})
.then(function() {
$rootScope.$broadcast('$stateChangeSuccess', toState, toParams, fromState, fromParams);
})
});
}) But it has a drawback: if the authorization check failed, the url will not revert back. |
Worked for me, thanks! Still a workaround... |
I tend to just use an |
@ProLoser Another approach for authorization. Thanks! |
Maybe it can be relevant in this issue: https://github.com/leonuh/ui-router.redirect |
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. |
At first I want to check authorization before state transition. So I use
$stateChangeSuccess
withe.preventDefault
method to intercept transition, sample code:It works fine until using $urlRouterProvider.when() for some url redirect:
Now if you visit url
/A
, then the browser would be trapped into an indefinite loop. I made a simple demo plunker here: http://plnkr.co/edit/lUkJx27HiaaNAJbF07n2?p=previewPlease open console and click 'A' link to see what I mean...
PS: This is an issue relative to #178
The text was updated successfully, but these errors were encountered: