我使用以下代码在角度4 app上将一个会话值存储在本地存储上。
this.http.post('http://localhost/salesneuronver4/Login/api/rest/Login/',value,
{ headers: this.headers}).map((res: Response) => res.json())
.subscribe(
res => { this.resnonseValue = res;
if(this.resnonseValue.status == 'success'){
this.getCookie();
// here I am storing session value
localStorage.setItem('userSession', this.resnonseValue.session_id);
// and its stored for current browser session
this.router.navigate(['/home']);
return false;
}else if(this.resnonseValue.status == 'expired'){
this.router.navigate(['/login']);
return false;
}
else{
this.errorMsg = this.resnonseValue.status;
}
},
err =>console.error(err)
);
}
现在当我关闭浏览器选项卡或整个浏览器时,本地存储的项userSesssion将丢失。如何在用户注销之前保持持久性?