且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 ionic 2 中使用带有侧边菜单的 nav.push

更新时间:2023-12-03 15:48:16

在您的 ion-menu 项目中使用 persistent="true" 怎么样?就像你在 Ionic2 文档中看到的一样:

What about using persistent="true" in your ion-menu item? Like you can see in Ionic2 docs:

持久菜单持久菜单在菜单中显示 MenuToggle 按钮导航堆栈中所有页面上的 NavBar.使菜单持久化在元素上设置persistent 为true.请注意,这将仅影响附加到菜单的导航栏中的 MenuToggle 按钮设置为 true 时,任何其他 MenuToggle 按钮都不会受到影响.

Persistent Menus Persistent menus display the MenuToggle button in the NavBar on all pages in the navigation stack. To make a menu persistent set persistent to true on the element. Note that this will only affect the MenuToggle button in the NavBar attached to the Menu with persistent set to true, any other MenuToggle buttons will not be affected.

所以你的 app.html 应该是:

<ion-menu [content]="content" persistent="true">

  <ion-toolbar>
    <ion-title>Pages</ion-title>
  </ion-toolbar>

  <ion-content>
    <ion-list>
      <button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
        {{p.title}}
      </button>
      <button menuClose ion-item (click)="logout()">Logout</button>
    </ion-list>
  </ion-content>

</ion-menu>

<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>