title: AWS Cognito Login and Angular 2 routing
body: <p>I'm not able to navigate to next page on success of AWS Cognito Login authentication from my angular 2 web app. Login is successful and I can see the token in console, but when I navigate on success of authentication I get below mentioned error. What is the mistake?</p>
  
  <p>It throws me this error:</p>
  
  <pre><code> EXCEPTION: Cannot read property 'navigate' of undefined
  </code></pre>
  
  <p>The code is as follows:</p>
  
  <p><strong>Component</strong></p>
  
  <pre><code>authenticateUser(loginCredentials:any){
  
         var authenticationData = {
              Username : loginCredentials.username,
              Password : loginCredentials.password
          };
          //console.log("authenticationData..",authenticationData);
          var authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails(authenticationData);
          console.log("authenticationDetails..",authenticationDetails);
          var poolData = {
              UserPoolId : "cognito user pool id ", // Your user pool id here
              ClientId : "cognito user pool client id" // Your client id here
          };
          //console.log("poolData..",poolData);
          var userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
          console.log("userPool..",userPool);
          var userData = {
              Username : loginCredentials.username,
              Pool : userPool
          };
          //console.log("userData..",userData);
          var cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
          console.log("cognitoUser..",cognitoUser);
  
          cognitoUser.authenticateUser(authenticationDetails, {
              onSuccess: function (result) {
                  console.log('access token + ' + result.getAccessToken().getJwtToken());
                  console.log('idToken + ' + result.idToken.jwtToken);
  
                  if(result.getAccessToken().getJwtToken() != null){
  
                      this.router.navigate(['nextPage']);
  
                  }
  
  
              },
  
              onFailure: function(err) {
                  console.log('error : ' + err);
                  alert(err);
              },
  
  
          })
  
     }
  </code></pre>