Angular onDestroy detected issue
As you know destory event isn't detected at the following cases
- enter key down at URL bar
- key down F5 key
Way to check the following case actually Token is alive
So I tried to check existing token the after above action. And I caught AppComponet class instance from ActivatedRoute. Token is saved into LocalStorage fast of all, so available to get manage data using the token. And return current page but Angular created new the component. I should destory all components before return current page but I'm not sure the way to that. Let me know the way if you know.
async canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Promise<boolean> {
// token check
let result = this.authFactiry.CheckToken();
if (result) {
// get manage data for user
result = await this.authFactiry.GetData();
}
if (result) {
this.destoryComponents(); // <- I would like to know this detail
return result;
}
const comp = this.route.Component; // this is AppComponent
// if check error navigate to login page
this.router.navigate(['login']);
return result;
}