对于处于类似情况的任何人,您都可以使用 angular route gaurds 添加条件/用户逻辑。在 Walkthrough.ts 模块中,我将值设置为存储:
ngOnInit(): void {
// save key to mark the walkthrough as visited so the next time the user vistis the app, he would be redirected to log in
Storage.set({
key: 'visitedWalkthrough',
value: 'true'
});
}
在 walkthrough.gaurd.ts 我检查相同的值并根据相同的值更改路线:
const { Storage } = Plugins;
@Injectable()
export class WalkthroughGuard implements CanActivate {
constructor(private router: Router) {}
async canActivate(): Promise<boolean> {
const { value } = await Storage.get({ key: 'visitedWalkthrough' });
if (value === 'true') {
// this is a returning user, don't show him the walkthrough
this.router.navigate(['auth']);
return false;
} else return true;
}
}
好教程在这里: