how can I call redirect if not logedIn in all pages constructors without repeating myself?
constructor(protected appCtrl: AppController) {
this.appCtrl.redirectIfNotLogedIn();
}
I suggest having a BaseComponent class that implements ionViewCanEnter that returns a boolean value.
Runs before the view can enter. This can be used as a sort of "guard" in authenticated views where you need to check permissions before the view can enter
export class BaseComponent{
constructor(){}
ionViewCanEnter(){
//check if logged in or not and return the boolean value
}
}
This component can be extended by all your pages.
export class MyPage extends BaseComponent{
//...
}
You could try to call your this.appCtrl.redirectIfNotLogedIn(); in the constructor of BaseComponent but I suggest you use the NavGuard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With