简体   繁体   English

Ionic5 侧边菜单 - 限制为特定视图

[英]Ionic5 side menu - limit to specific view

I followed the documentation and added the menu into app.component.html as我按照文档并将菜单添加到app.component.html

<ion-app>
  <ion-split-pane contentId="main-content">
    <ion-menu contentId="main-content" type="overlay">
      <ion-content>
        <ion-list no-lines width="10">
          <ion-list-header>
            <h2>MyApp</h2>
          </ion-list-header>  
          <ion-menu-toggle auto-hide="true">
            <ion-item [routerLink]="['/forecast']">
              Foo Bar
            </ion-item>
          </ion-menu-toggle>
    ....
</ion-menu>
    <ion-router-outlet id="main-content"></ion-router-outlet>
  </ion-split-pane>
</ion-app>

Now, that menu is accessible for all views by swiping, including the login view which it should not be.现在,所有视图都可以通过滑动访问该菜单,包括它不应该访问的登录视图。 How can I limit the menu to a specific view only without breaking the ion-split-pane ?如何在不破坏ion-split-pane情况下将菜单限制为特定视图?

Do it like this.像这样做。 Disable the menu by default默认禁用菜单

<ion-menu contentId="main-content" type="overlay" disabled>

And then, the view where you want to show it, put this in the controller然后,你想显示它的视图,把它放在控制器中

import { MenuController } from '@ionic/angular';

constructor(
  public menuCtrl: MenuController){
  this.menuCtrl.enable(true);
}

Use: MenuController to enable and disable menu.使用: MenuController启用和禁用菜单。

import { MenuController } from '@ionic/angular';

constructor(private menu: MenuController) { }

ionViewWillEnter(){
   this.menu.enable(true);
   this.menu.enable(true, 'YourMenuId');  // or you can target it with your ID
}

Menu Doc: https://ionicframework.com/docs/api/menu菜单文档: https : //ionicframework.com/docs/api/menu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM