Saturday, 15 March 2014

angularjs - Angular ui-router $state.go is not redirecting inside resolve -


itemprop = "text">

In my angle app, I see if the user is land on the landing page and is already authenticated, then it will be sent to the home page Redirect to.

  .state ('landingpage', {abstract: "true", url: "/ landing page", template url: "app / landing page / landing page html", solve: { AutoLanguage check: ['$ State', '$ window', function ($ state, $ window) {if ($ window.localStorage.access_token! = Null) {if ($ window.sessionStorage.access_token == null) {$ Window.sessionStorage.access_token = $ Window.localStorage.access_token;} UserInfoService.SetUserAuthenticated (true); // This return $ state.go ('app.home') is not redirecting;}}}}})  

The problem is that although all the resolution code is run successfully, the user app.home Not being redirected. Someone can tell why this happens?

Note : There is also a resolution of the state 'app' in which it receives data appearing in 'AP home' condition. / P>

Your problem can be two solutions

  • Most First you can emit an event and the listener will handle your state infection. You can implement the listener anywhere in the parent controller

  • Secondly, you can apply the $ stateChangeStart hook and check your redirection status

    < Pre> $ root 'scope' $ ('$ change state' start, function (event, toastate) {if (toState.name === 'landing page') {if (! IsAuthenticated ()) {// Check that the user is allowed to transition event.preventDefault (); // Prevent migration to default state $ state.go ('home.dashboard');}}});

No comments:

Post a Comment