我正在尝试将用户重新登录到登录页面,如果没有验证我的问题我无法看到我的代码在运行时如果用户不是auth,
userRoute.$inject = ['Router','$rootScope', '$state'];
function userRoute(Router,$rootScope,$state) {
$rootScope.$on("$stateChangeError", function (event, toState, toParams, fromState, fromParams, error) {
// We can catch the error thrown when the $requireSignIn promise is rejected
// and redirect the user back to the home page
debugger;
if (error === "AUTH_REQUIRED") {
$state.go("login");
}
});
在我的路线上我做了:
controller: 'list.controler',
controllerAs: 'vm',
resolve: {
"firebaseUser": function (authService) {
// If the promise is rejected, it will throw a $stateChangeError
return authService.firebaseAuthObject.$requireSignIn();
}
}
});
答案 0 :(得分:0)
尝试:
$state.go("login"); //
.state("login", {
url:"/login",
controller: "loginCtrl",
templateUrl: "my/path/login.html"
})
答案 1 :(得分:0)
我建议您在js文件中使用moduleName.run()函数,无论是app.js还是其他文件名,它看起来都是这样的:
//your moduleName and it's dependencies here
.run(["$rootScope", "$state", function($rootScope, $state) {
$rootScope.$on("$stateChangeError", function(event, toState, toParams, fromState, fromParams, error) {
// We can catch the error thrown when the $requireSignIn promise is rejected
// and redirect the user back to the login page
if (error === "AUTH_REQUIRED") {
return $state.go("login");
}
});
}])
在index.html中
<script src=".../angular-ui-router.min.js"></script>
<script src=".../stateEvents.js"></script>
您还需要建立一个登录状态,如下所示:
.config(['$routeProvider', '$stateProvider', function($routeProvider, $stateProvider) {
$stateProvider.state('login', {
name: 'login',
url: '/login',
templateUrl: 'login/login.html',
controller: 'loginCtrl'
})
}])