Prevent Page from Loading while ViewWillEnter lifeCycle


#1

Hi
I am trying to block certain views for App user based on Role,
My logic is to check the View I am just entering, and block the view before it completely loads, so that he will not have access to the restricted pages.

any ways to do so with nav Guards

ā€“ in app.component.ts

 this.nav.viewWillEnter.subscribe((view) => {
  let currentModule = view.instance.constructor.name;
 // here I am checking currentModule 
// after this I want to conditionally load the pages, 
// I am not able to prevent page from entering, 
 });

#2

You can use

ionViewCanEnter(): boolean {
if (!this.authProvider.isAdmin) {
 return false;
 }
 //etc...
}

In the page itself. Something like the above example


#3

Okay, looks cool.
Any ways to do it in one place (like app.component) , rather than adding it in each and every page of the application.