disable menu on login page ionic 4

2020-03-19 14:41发布

I use the beta of ionic 4 for the first time. I try to disable the menu on a login page, but i have some trouble.

I've created the app with ionic-cli and the sidemenu template, then I generated a login page.

I removed the <ion-split-pane> from the app.component.html

I modified the app-routing.module.ts to redirect to my login screen. In my login file, I tried to put an ngOnInit event to disable the menu on this specific page

import { Component, OnInit, AfterContentInit, AfterViewInit,OnDestroy } from '@angular/core';
import { MenuController } from '@ionic/angular';
@Component({
  selector: 'app-login',
  templateUrl: './login.page.html',
  styleUrls: ['./login.page.scss'],
})
export class LoginPage implements OnInit, AfterContentInit, AfterViewInit,OnDestroy {
  constructor(public menuCtrl: MenuController) {}
  ngOnInit() {
    this.menuCtrl.enable(false);
    this.menuCtrl.swipeEnable(false);
  }
  ngAfterContentInit()  {
    this.menuCtrl.enable(false);
    this.menuCtrl.swipeEnable(false);
  }
  ngAfterViewInit() {
    this.menuCtrl.enable(false);
    this.menuCtrl.swipeEnable(false);
  }
  ngOnDestroy() {
    this.menuCtrl.enable(true);
    this.menuCtrl.swipeEnable(true);
  }
}

I alto tried with an id set in ion-menu

<ion-menu swipeEnabled="true" #menu>

and change my code with

this.menuCtrl.enable(false, 'menu');

It's not working, can some one help me please.

Thank's

5条回答
▲ chillily
2楼-- · 2020-03-19 15:21

In my case in ionic 4 app, I did the following in welcome.page.ts file. welcome.page.ts is the page in which I want to hide split pane.

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

constructor( public menuCtrl: MenuController){}

ionViewWillEnter() {
 this.menuCtrl.enable(false);
}
查看更多
Animai°情兽
3楼-- · 2020-03-19 15:22

Solved my issue using

<ion-menu [swipeGesture]="false" ...>
查看更多
Evening l夕情丶
4楼-- · 2020-03-19 15:28

Ionic 4 you would use the disabled property on ion-menu to hide on login.

<ion-menu [disabled]="!isLoggedIn"></ion-menu>
查看更多
看我几分像从前
5楼-- · 2020-03-19 15:30

Instead of manually disabling it i think you should disable the swipe in ion-menu like this:

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

and in the login page

<ion-header>

 <ion-navbar>
   <ion-title text-center>Login</ion-title>
 </ion-navbar>

</ion-header>

This way menu will be disabled in the Login Page.

查看更多
Viruses.
6楼-- · 2020-03-19 15:35

Ionic 4.0.0 still supports ionViewWillEnter, use below code:

ionViewWillEnter() {
  this.menuCtrl.enable(false);
}

You can find full example here.

查看更多
登录 后发表回答