当用户提交名称时,它会保存在移动设备的本地存储中并重定向到第二页,但用户关闭并重新打开它从第一页加载的应用程序。下面是我的代码。
这是我的 Auth Guard 代码
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): boolean {
if (localStorage.getItem('petData') != null) {
return true;
} else {
this.route.navigateByUrl('/');
return false;
}
}
这个是路由
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./home/home.module').then(m => m.HomePageModule)
},
{
path: '',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: 'dashboard',
canActivate: [LocalGuardGuard],
loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardPageModule)
},
];
这是第一个页面提交事件。
saveData() {
// this.storage.set('petData', JSON.stringify(this.petData.petName));
localStorage.setItem('petData', this.petData.petName);
Swal.fire({
// title: this.petData.petName,
title: 'It is a not pet anymore, It is a ' + this.petData.petName,
timer: 2000,
timerProgressBar: true
});
this.router.navigateByUrl('/dashboard');
}