【问题标题】:How to set rootPage conditionally in Ionic3 [duplicate]如何在 Ionic 3 中有条件地设置根页面 [重复]
【发布时间】:2017-09-25 14:12:17
【问题描述】:

我正在尝试为应用程序中的第一个计时器设置教程页面,并为其他人设置登录页面。如果用户已经浏览了教程页面,我将在 localstorage 中设置键值。

export class MyApp {
rootPage: any = LoginPage;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
        statusBar.styleDefault();
        if(!localStorage.getItem( 'tutorial' )) {
            this.rootPage = TutorialPage;
        }
        splashScreen.hide();
    });
  }
}

以上代码工作正常,但设置教程页面有延迟,登录页面首先查看,然后教程页面出现。我想知道我这样做的方式是否正确,或者我遗漏了什么?

【问题讨论】:

  • 删除 rootPage: any = LoginPage; 仅使用 rootPage: any; 并将 else 块放入 constructor
  • 感谢@hrdkisback 的回答。成功了!

标签: angular ionic2 ionic3 ionic-native


【解决方案1】:

请使用以下代码

export class MyApp {
rootPage: any;

constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
    platform.ready().then(() => {
        statusBar.styleDefault();
        if(!localStorage.getItem( 'tutorial' )) {
            this.rootPage = TutorialPage; // user can user this.nav.setRoot(TutorialPage);
        }else{
            this.rootPage = LoginPage; // user can user this.nav.setRoot(LoginPage);
        }
        splashScreen.hide();
    });
  }
}

我希望它对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 2018-12-31
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    相关资源
    最近更新 更多