【发布时间】:2016-04-25 09:39:26
【问题描述】:
这个解析函数在其他任何地方都有效,我很困惑为什么当承诺被拒绝时配置文件页面仍在执行。我们通过登录、从存储中删除令牌然后尝试导航到配置文件页面来产生此错误。它会完成所有身份验证步骤,然后注销。它到达了重定向行,但它仍然加载配置文件页面,由于身份验证已被清除而引发错误。
您能提供的任何帮助都会很棒。如果您需要更多信息,请告诉我。
app.config('$routeProvider')
.when('/profile', {
templateUrl: '/templates/profile.html',
controller: 'ProfileController',
resolve: {
auth: function (SessionService) {
SessionService.resolve()
}
}
}).
otherwise({
redirectTo: '/login'
})
function resolve () {
if (self.isAuthenticated()) {
return $q.when({auth: true})
} else {
$q.reject({auth: false})
self.logout() // first we go here
}
}
}
function logout () {
var auth = self.storage()
if (...) {
...
} else {
self.clearUserAuthentication() // then here
$location.path('/login') // it redirects here, but still initializes the profile controller
}
}
【问题讨论】:
标签: javascript angularjs resolve