0

我有使用 ion-slides 构建的应用程序演练/介绍,它被加载为 app.routing.module.ts 中的默认页面。

{
    path: '',
    redirectTo: 'walkthrough',
    pathMatch: 'full'
  },{
    path: 'walkthrough',
    loadChildren: () => import('./walkthrough/walkthrough.module').then(m => m.WalkthroughPageModule)
  }

我只想在应用程序第一次启动时显示这个,所以我的问题是如何在应用程序路由模块中配置应用程序路由以设置一次打开页面?我阅读了文档,但找不到参考。

4

1 回答 1

1

对于处于类似情况的任何人,您都可以使用 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;
  }
}

好教程在这里

于 2021-02-01T21:53:57.767 回答