javascript - Redirection after login - Stack Overflow

I have a redirection problem in my app. These are my state providers:testApplication.config(function($s

I have a redirection problem in my app. These are my state 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 don't get 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 get redirected to the profile page. How can I fix that?

I have a redirection problem in my app. These are my state 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 don't get 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 get redirected to the profile page. How can I fix that?

Share Improve this question edited Jan 3, 2017 at 23:27 Don't Panic 41.8k11 gold badges68 silver badges85 bronze badges asked Jan 5, 2015 at 20:37 nikitznikitz 1,0912 gold badges12 silver badges36 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 7

Try

$state.go('app.profile') 

instead of

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

I hope this helps others too.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744151687a4560672.html

相关推荐

  • javascript - Redirection after login - Stack Overflow

    I have a redirection problem in my app. These are my state providers:testApplication.config(function($s

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信