ionViewCanEnter() doesn’t work.
I use ionic version 3.20.0.
Please forgive me that my English is not good.
I want to enter PageB only when logged in. The following code is based on ionic’s official document. I check the login status and login function using firebase. When I executed the following code, I put it in PageB whether it is in login status or logout status. Is my way of using ionViewCanEnter wrong?
What I would like to implement is to switch to PageB from Page A, enter PageB if logged in, and transition to login page if logged out.
export class PageA{
constructor(
public navCtrl: NavController
){}
pushPage(){
this.navCtrl.push(PageB);
}
}
export class PageB(){
constructor(
public navCtrl: NavController
){}
ionViewCanEnter(): boolean{
firebase.auth().onAuthStateChanged(function(user) {
if(user){
// login
return true;
} else {
// logout
return false;
}
}
}