2017-09-25 17 views
0

我想为应用程序中的第一个定时器和其他人的登录页面设置教程页面。如果用户已经浏览了教程页面,我将在localstorage中设置关键值。如何在Ionic3中有条件地设置rootPage

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(); 
    }); 
    } 
} 

上面的代码工作正常,但在设置教程页面和登录页面查看第一则教程页面快到了延迟。我想知道我是以正确的方式做这件事还是错过了一些东西?

+1

删除'rootPage:any = LoginPage;'只使用'rootPage:any;'并将'else'块放在'constructor'中。 – hrdkisback

+0

感谢@hrdkisback为您的答案。有效! – Shubham

回答

0

请使用如下代码

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(); 
    }); 
    } 
} 

我希望它为你工作。

相关问题