Redirect after login

I have a redirect problem in my application. These are my government providers:

testApplication.config(function($stateProvider, $urlRouterProvider) {

$stateProvider

.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})

.state('app2', {
url: "/app2",
abstract: true,
templateUrl: "templates/menu2.html",
controller: 'AppCtrl'
})

.state('app2.login', {
url: "/login",
views: {
  'menuContent': {
    templateUrl: "templates/login.html",
    controller: 'LoginCtrl'
  }
}
})

.state('app.profile', {
url: "/profile",
views: {
  'profile' :{
      templateUrl: "templates/profile.html",
      controller: "ProfileCtrl"
  }
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app2/login');
});

      

My AppCtrl is empty and this is my LoginCtrl:

testApplication.controller('LoginCtrl', function($scope, $location){ 
 $scope.fbLogin = function() { 
   openFB.login( function(response) { 
     if (response.status === 'connected') {
       // This runs on success 
        console.log('Facebook login succeeded');
        $scope.$apply( function () { $location.path('profile') } ); 
     } else { 
          alert('Facebook login failed'); 
     } 
   }, {scope: 'email,publish_actions,user_friends'}
  ); 
 }; 
})

      

The problem is that I am not redirected after login. But if I change

$urlRouterProvider.otherwise('/app2/login');

      

to

$urlRouterProvider.otherwise('/app/profile');

      

And go manually to "# / app2 / login" to login. I am redirected to the profile page. How can I fix this?

+3


source to share


1 answer


Try

$state.go('app.profile') 

      

instead



$scope.$apply( function () { $location.path('profile') } );

      

I hope this helps others too.

+7


source







All Articles