我有应用演练/介绍构建使用离子幻灯片,这是加载作为默认页面在app.routing.module.ts。
{
path: '',
redirectTo: 'walkthrough',
pathMatch: 'full'
},{
path: 'walkthrough',
loadChildren: () => import('./walkthrough/walkthrough.module').then(m => m.WalkthroughPageModule)
}我只想在应用程序第一次启动时展示这一点,所以我的问题是如何配置应用路由模块中的应用路由,使其只设置一次打开页面?我读了文档,却找不到参考资料。
发布于 2021-02-01 21:53:57
对于任何处于类似情况的人,您都可以使用角路由算法来添加条件/用户逻辑。在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;
}
}好教程这里:
https://stackoverflow.com/questions/65872648
复制相似问题