用户成功登录后,我希望该页面重定向到主页。我的代码目前看起来像:
function MainCtrl(user, auth) {
var self = this;
function handleRequest(res) {
var token = res.data ? res.data.token : null;
if(token) { $location.path('/'); }
self.message = res.data.message;
}
self.login = function() {
user.login(self.username, self.password)
.then(handleRequest, handleRequest)
}
}
为什么行$location.path('/');
不起作用,是我应该实际拥有重定向的地方?
路线配置部分:
.config(function($routeProvider){
$routeProvider.when("/",
{
templateUrl: "views/home.html"
}
)
.when("/login",
{
templateUrl: "views/login.html"
}
)
.when("/register",
{
templateUrl: "views/register.html"
}
);
})
感谢。