Ionic 5 menu doesn't show up

耗尽温柔 提交于 2021-01-28 18:01:53

问题


I have a demo application where I want to insert a menu. Unfortunately I can't get this menu to appear in the header. I've tried different approaches, but I can't find the solution.

My app.component.html looks like this:

<ion-app>
  <app-header></app-header>
  <ion-router-outlet id="main-content"></ion-router-outlet>
  <app-footer></app-footer>
</ion-app>

My header.component.html like this:

<ion-menu side="start" contentId="main-content">
  <ion-header>
    <ion-toolbar color="primary">
      <ion-buttons slot="start">
        <ion-back-button></ion-back-button>
      </ion-buttons>
      <ion-title>
        My App
      </ion-title>
    </ion-toolbar>
  </ion-header>
  <ion-content>
    <ion-list>
      <ion-item>
        <ion-label>Account</ion-label>
      </ion-item>
      <ion-item>
        <ion-label>Start game</ion-label>
      </ion-item>
      <ion-item>
        <ion-label>Scores</ion-label>
      </ion-item>
      <ion-item>
        <ion-label>Rules</ion-label>
      </ion-item>
    </ion-list>
  </ion-content>
</ion-menu>

The menu or header no longer appears after I insert the menu.

What am I doing wrong?


回答1:


You should insert this code in app.component.html

<ion-app>
  <ion-split-pane contentId="main-content">
    <ion-menu class="custom-menu" side="end" contentId="main-content">

      <ion-content>
        <ion-list class="menu-list" lines="none" no-padding>
          <ion-menu-toggle auto-hide="false" *ngFor="let p of appPages" class="menu-toggle-item">
            <ion-item lines="none" class="menu-item">
              <ion-label>
                {{p.title}}
              </ion-label>
              <!-- Lorem ipsum dolor sit amet consectetur adipisicing elit. -->
            </ion-item>
          </ion-menu-toggle>

          </ion-list>
      </ion-content>
    </ion-menu>
    <ion-router-outlet id="main-content"></ion-router-outlet>
  </ion-split-pane>
</ion-app>

inside child page use ionic menu button

<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-menu-button></ion-menu-button>
    </ion-buttons>
    <ion-title>Title</ion-title>
  </ion-toolbar>
</ion-header>



回答2:


In order to keep the ion-back-button or ion-menu-button there even if the context is lost. Use auto-hide attribute in Ionic 4 onwards.

 <ion-menu-button auto-hide="false"></ion-menu-button>


来源:https://stackoverflow.com/questions/60775822/ionic-5-menu-doesnt-show-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!