我有一个 ionic 5 项目。 成功登录并关闭应用程序后 再次打开应用程序后显示 1 秒登录页面,然后重定向到路由页面,我的情况是主页 如何使用guard防止它显示页面
我已经完成这些并遇到设备启动问题
路线页面
path: '',
canActivate:[LoginGuard],
children:[
]
登录卫士页面
public async canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Promise<any> {
let res = await this.storage.get('loggedIn');
console.log(res)
if (res == null) res = 0
if(res == 0){
return this.route.parseUrl('/login');
}else if (res == 1) {
return this.route.parseUrl('/home');
}
}
只是一个疯狂的猜测,但你能尝试下面的代码吗?
public canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): any {
let res = this.storage.get('loggedIn');
console.log(res);
if (res == null) {
res = 0;
}
if(res == 0){
return this.route.navigate(['/login']);
}else if (res == 1) {
return this.route.navigate(['/home']);
}
}