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?
Try
$state.go('app.profile')
instead of
$scope.$apply( function () { $location.path('profile') } );
I hope this helps others too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.