问题
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