Skip to content
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 #2236

Closed
ionescuvictor opened this issue Sep 10, 2015 · 4 comments
Closed

Redirect loop #2236

ionescuvictor opened this issue Sep 10, 2015 · 4 comments

Comments

@ionescuvictor
Copy link

I have this code.Here is the plnkr . http://plnkr.co/edit/FtWBfKaZ9VsCN1tT6nef?p=preview

on the

App.run(function ($rootScope, currentUser, $state, $location) {

$rootScope.$on('$stateChangeStart',
       function (event, toState, toParams, fromState, fromParams) {

           if (localStorage.getItem("Token") == null && toState.name != "loginPage") {
               event.preventDefault();
               $state.go('loginPage', { redirectUrl: toState.name });
               return;
           }

       });

});

The problem is that it goes around and around in a loop, until i get max 10 digest error.My javascript knowledge is rather limited.Can somebody please help me?

@ionescuvictor
Copy link
Author

well i found the answer.I had to do this, perhaps somebody explain what is going on? and maybhe fix this bug?

  $urlRouterProvider.otherwise(function ($injector, $location) { // nasty bug.
        var $state = $injector.get("$state");
        $state.go("home");
    });

@eddiemonge
Copy link
Contributor

Can you post a plnkr example please?

@ionescuvictor
Copy link
Author

http://plnkr.co/edit/FtWBfKaZ9VsCN1tT6nef?p=preview

here you go.

Open up the console and you can clearly see 10 digest cycles reached.

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D

And thank you for the interest.Unfortunatly im very newb when it comes to angular and javascript in general.

@eddiemonge
Copy link
Contributor

Duplicate of #2238

christopherthielen added a commit that referenced this issue Jan 23, 2016
ExpFront pushed a commit to ExpFront/ui-router that referenced this issue Jun 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants