例如状态值为1是入口页为登录页,状态值为2时,入口页为首页,状态值为3时入口页为验证身份页等依次类推,动态的设置入口页rootpage。
实现如下:
1.将rootpage的初始值设置为空,
2.然后在app.component.ts里面设置项目启动的时候调用接口,获取返回的娥状态值,
3.根据不同的状态值来设置不同的rootpage页面
export class MyApp { rootPage:any = ""; public AccountId=localStorage.getItem("AccountId"); constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,public mineService: MineService) { platform.ready().then(() => {//当平台准备好的时候运行 // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. statusBar.styleDefault(); splashScreen.hide(); mineService.ionienter(this.Id).then((data:string)=>{//调用接口 let reslObj=JSON.parse(data); console.log(reslObj); console.log(0); console.log(reslObj.Status); if(reslObj.IsOK==1){ if(reslObj.Status=="1"){//根据返回的状态值来跳转页面 console.log(1); this.rootPage="HomePage"; }else if(reslObj.Status=="2"){ console.log(2); this.rootPage="MinePage1"; }else if(reslObj.Status=="3"){ console.log(3); this.rootPage="LoginPage"; } } }); }); } }