Moc*_*ani 2 typescript ionic2 angular
我想在localStorage上已经有令牌时将页面重定向到主页(覆盖登录页面).怎么做?我在app.component.ts上的构造函数()上有以下代码,但它在请求完成之前首先显示登录
statusBar.backgroundColorByHexString('#D32F2F');
splashScreen.hide();
if(localStorage.getItem('token')){
authProvider.silent_login().subscribe(res => {
console.log(res);
if(res.error==0){
this.rootPage = HomePage;
}
})
}
Run Code Online (Sandbox Code Playgroud)
你能不能
@ViewChild(Nav) nav: Nav;
rootPage: any = null; // Initialize it as null
pages: Array<{title: string, component: any}>;
constructor(public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen,
public commonProvider: CommonProvider) {
this.commonProvider.retrieve("is_login").then(loggedIn => {
// Assign the right page after checking the status
this.rootPage = loggedIn ? TabsPage : SigninPage;
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1158 次 |
最近记录: |