'Correct approach to enable or disable sidemenu on certain pages in Ionic 3?

I have gone through this SO link Ionic - How to remove sidemenu on login page only? and tried the solutions provided here. Based on the solutions provided in the above link it seems like the simplest way to remove sidemenu from certain pages in Ionic 3 is to use the following code snippet in each page.

login.ts, register.ts, forgot-password.ts (all the files NOT requiring sidemenu)

constructor(public navCtrl: NavController, public navParams: NavParams, private menu: MenuController) {
    this.menu.enable(false);
}

home.ts, account-settings.ts (all the files requiring sidemenu)

constructor(public navCtrl: NavController, public navParams: NavParams, private menu: MenuController) {
    this.menu.enable(true);
}

Based on the above SO solution provided I had to go in each of the page and disable the sidemenu by setting the flag as false and viceversa for the pages requiring sidemenu.

Is this a better approach than this?



Solution 1:[1]

You can try :-

Open src/app/app.html and add an ID to your element So that this,

Becomes this.

Open login.html and remove the code from so that the menu will not display on the page. Open login.ts and import the MenuController from ionic/angular. In the constructor set enable() on MenuCtrl to false and add the menu ID as the second parameter. Even though the menu isn’t showing, doing this will prevent the user from swiping to open the menu.

  • constructor( public navCtrl: NavController, public menuCtrl: MenuController ) { this.menuCtrl.enable(false, 'myMenu'); }

follow :- https://forum.ionicframework.com/t/how-to-disable-side-menu-are-some-pages/112968/2

Solution 2:[2]

I think you can use menuToggle directive like so:

<ion-navbar>
    <ion-buttons start>
      <button ion-button menuToggle="false">
        <ion-icon name="menu"></ion-icon>
      </button>
    </ion-buttons>
</ion-navbar>

Basically adding it to those pages you need top left corner button to show up and setting it to false for the pages you don't want users to see button calling side menu

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sunil kalwani
Solution 2 Sergey Rudenko