Search code examples
angularionic-frameworkionic4

Ionic 4 2 menus on same page


I'm trying to add multiple menus to the same page in ionic however when I open up one of them I cant click on any of the links.

In my app component I have one of the menus in there and a separate component for the right menu.

<ion-app>
  <ion-menu menuId="mainMenu" side="start" contentId="mainMenu" swipe-gesture="false">
    <ion-header>
      <ion-toolbar>
        <ion-title>Pages Menu</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content>
      <ion-list>
        <ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">
          <ion-item [routerDirection]="'root'" [routerLink]="[p.url]">
            <ion-icon slot="start" [name]="p.icon"></ion-icon>
            <ion-label>
              {{p.title}}
            </ion-label>
          </ion-item>
        </ion-menu-toggle>
      </ion-list>
    </ion-content>
  </ion-menu>
  <app-side-menu></app-side-menu>
  <ion-router-outlet id="mainMenu"></ion-router-outlet>
</ion-app>

This is my side-menu component

<ion-menu side="end" menuId="sideMenu" id="sideMenu" contentId="sideMenu" swipe-gesture="false">
  <ion-header>
    <ion-toolbar color="primary">
      <ion-title>Menu</ion-title>
    </ion-toolbar>
  </ion-header>
  <ion-content>

    <div *ngFor="let p of menu">

      <ion-menu-toggle *ngIf="p.url">
        <ion-item [routerLink]="p.url" routerDirection="root" routerLinkActive="active">
          <ion-icon [name]="p.icon" slot="start"></ion-icon>
          <ion-label>
            {{ p.title }}
          </ion-label>
        </ion-item>
      </ion-menu-toggle>

      <ion-item button *ngIf="p.children?.length > 0" (click)="p.open = !p.open" [class.active-parent]="p.open" detail="false">
        <ion-icon slot="start" name="arrow-forward" *ngIf="!p.open">,/</ion-icon>
        <ion-icon slot="start" name="arrow-down" *ngIf="p.open">,/</ion-icon>
        <ion-label>{{ p.title }}</ion-label>
      </ion-item>

      <ion-list *ngIf="p.open">
        <ion-menu-toggle>
          <ion-item class="sub-item"  *ngFor="let sub of p.children" [routerLink]="sub.url" routerDirection="root" routerLinkActive="active">
            <ion-icon [name]="sub.icon" slot="start"></ion-icon>
            <ion-label>
              {{ sub.title }}
            </ion-label>
          </ion-item>
        </ion-menu-toggle>
      </ion-list>
    </div>
  </ion-content>
</ion-menu>

and on my page that i want to display both menus this is the header

<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-menu-button menu="mainMenu" autohide="false"></ion-menu-button>
    </ion-buttons>

    <ion-buttons slot="end">
      <ion-menu-button menu="sideMenu" autohide="false"></ion-menu-button>
    </ion-buttons>

    <ion-title>
      Home
    </ion-title>
  </ion-toolbar>
</ion-header>

everything shows correctly, the left menu works fine but when I open the right menu I can't click on anything or click away.


Solution

  • Try setting side menu's contentId to the ID of the router outlet that has to render the route's content. In this case, I think you want to point to "mainMenu":

    since:

    <ion-router-outlet id="mainMenu"></ion-router-outlet>
    

    you need to point your side menu at it:

    <ion-menu side="end" menuId="sideMenu" id="sideMenu" contentId="mainMenu" swipe-gesture="false">
        ...
    </ion-menu>