nik*_*itz 3 javascript redirect angularjs
我的应用程序中有重定向问题.这些是我的州提供者:
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');
});
Run Code Online (Sandbox Code Playgroud)
我的AppCtrl为空,这是我的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'}
);
};
})
Run Code Online (Sandbox Code Playgroud)
问题是登录后我没有被重定向.但如果我改变
$urlRouterProvider.otherwise('/app2/login');
Run Code Online (Sandbox Code Playgroud)
至
$urlRouterProvider.otherwise('/app/profile');
Run Code Online (Sandbox Code Playgroud)
然后手动转到"#/ app2/login"登录我会被重定向到个人资料页面.我该如何解决这个问题?
尝试
$state.go('app.profile')
Run Code Online (Sandbox Code Playgroud)
代替
$scope.$apply( function () { $location.path('profile') } );
Run Code Online (Sandbox Code Playgroud)
我希望这对其他人也有帮助.
| 归档时间: |
|
| 查看次数: |
6789 次 |
| 最近记录: |