当 localStorage 上已有令牌时,我想将页面重定向到主页(覆盖登录页面)。怎么做?我在 app.component.ts 的constructor() 上有以下代码,但它在请求完成之前首先显示登录信息
statusBar.backgroundColorByHexString('#D32F2F');
splashScreen.hide();
if(localStorage.getItem('token')){
authProvider.silent_login().subscribe(res => {
console.log(res);
if(res.error==0){
this.rootPage = HomePage;
}
})
}
你能喜欢吗
@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;
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句