我正在使用登录并希望重定向到已保存的网址状态。
login(username: string, password: string) {
return this.http.post('/api/authenticate', JSON.stringify({ username: username, password: password }))
.map((response: Response) => {
// login successful if there's a jwt token in the response
let user = response.json();
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
this.alertService.success("Login success", true);
this.location.back();
}
});
}
这是我在这里观察的登录信息
login() {
this.loading = true;
this.authService.login(this.model.username, this.model.password)
.subscribe(() => {
this.router.navigate([this.returnUrl]);
},
error => {
this.alertService.error(error);
this.loading = false;
});
}
问题:this.router.navigate([this.returnUrl]);
不导航到returnUrl。但是当我正在调试时,保存了正确的URL。