0

Here is my route config:

$stateProvider
      .state('login', {
        url: '/',
        templateUrl: function(){
          return 'app/login/login.html';
        },
        controller: 'loginCtrl as ctrl',
        data: {
          requireLogin: false
        }
      })
      .state('loginSerial', {
        url: '/login/createCase?sn=',
        templateUrl: function(){
          return 'app/login/login.html';
        },
        controller: 'loginCtrl as ctrl',
        data: {
          requireLogin: false
        }
      })

on $stateChangeStart - I am redirecting as :

if( !$rootScope.isUserLoggedIn && !$rootScope.serialLogin ){

        console.log('no one is logged in!', toParams.sn);
        $state.go('/login/createCase',{sn:toParams.sn});;
        event.preventDefault();
        return;

      } 

It works fine. But I am getting following error :

angular.js:11706 Error: Could not resolve '/login/createCase' from state ''
    at Object.transitionTo (angular-ui-router.js:3179)
    at Object.go (angular-ui-router.js:3107)
    at index.route.js:152
    at Scope.$broadcast (angular.js:14889)
    at Object.transitionTo (angular-ui-router.js:3272)
    at Array.<anonymous> (angular-ui-router.js:2383)
    at Object.invoke (angular.js:4219)
    at handleIfMatch (angular-ui-router.js:1868)
    at angular-ui-router.js:1925
    at check (angular-ui-router.js:2041)

How to solve this? and what is wrong with my side? any one help me?

2 Answers 2

1

You should pass state name, not state's url

// not this
$state.go('/login/createCase',{sn:toParams.sn});
// but that
$state.go('loginSerial',{sn:toParams.sn});

Extend, also, before any redirection, I would strongly suggest to check, if we are not already being redirected:

if(toState.name === 'loginSerial'){
    return; // do not continue in redirection, if already redirected
}
Sign up to request clarification or add additional context in comments.

4 Comments

Ready to assist, but you should show more.. html template.. and even better... some plunker. There are some similar Q & A with plunkers stackoverflow.com/q/26135382/1679310
As a test can I update my url and test like this: http://localhost:3000/login/createCase?sn=3000 -
Well, are you sure, that current state (before redirection) also has sn param? I doubt... that every has that.. so you should do $state.go('loginSerial',{sn:toParams.sn || 3000});
Well, there are parts still missing, e.g. login controller. We should do the check if use was redirected very soon. For example this if( !$rootScope.isUserLoggedIn && !$rootScope.serialLogin && toState.name === 'loginSerial' ) should be if( !$rootScope.isUserLoggedIn && !$rootScope.serialLogin && toState.name !== 'loginSerial' ) - otherwise it will create a lop - here is a really working handling, pretty similar to your issue.. try to use that snippet stackoverflow.com/a/25029259/1679310
0

$state.go requires that you pass in a state name and not a state url. So you'll need to execute

$state.go('loginSerial', {params});

2 Comments

Yes, Now the error gone. But page not displayed, But before I got login page displayed with error. anything need to go further fine tune?
@user2024080 remove the = in your url for your state /login/createCase?sn= so that it's /login/createCase?sn. This is based on the docs github.com/angular-ui/ui-router/wiki/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.