Ionic Side Menu

Learn how to use and customize a sid menu component in an Ionic angular app.

Ionic Menu

Navigation is indeed one of the most important elements of user experience. The Menu component is a navigation drawer that slides in from one side of the current view. In Ionic apps is very easy to add a Side Menu component.

By default, it slides in from the left, but the side can be overridden. This is important for RTL apps.

After you go through the authentication pages of the template and you log in into the app, you will see that there are two ways to navigate into the app pages:

  • tabs

  • side menu

To learn more about the navigations used in this ionic template go to the Navigation section.

You can find the code of this side menu insrc/app/app.component.html and src/app/app.component.ts

We use the ion-menu component from the Ionic UI Components. You can either define the menu items in the markup (.html) or in the component (.ts).

Let's see an example.

The following code defines the Forms section of the ion-menu with two items.

With the [routerLink] you define the route where you want to navigate to when clicking the ion-item.

Remember that those routes are defined in src/app/app-routing.module.ts

The icons can be set either using Ionicons, like we do in the Form Filters option, or using custom svg icons. This template includes lots of custom and beautiful svg icons that you can use in your ionic apps.

app.component.html
<ion-list>
  <ion-list-header>
    <ion-label>Forms</ion-label>
  </ion-list-header>
  <ion-menu-toggle autoHide="false">
    <ion-item [routerLink]="['/forms-and-validations']">
      <ion-icon slot="start" src="./assets/custom-icons/side-menu/forms.svg"></ion-icon>
      <ion-label>
        Forms & Validations
      </ion-label>
    </ion-item>
    <ion-item [routerLink]="['/forms-filters']">
      <ion-icon slot="start" name="options-outline"></ion-icon>
      <ion-label>
        Filters
      </ion-label>
    </ion-item>
  </ion-menu-toggle>
</ion-list>

Also, other menu item options are defined as a list in the AppComponent and iterated in the html. Let's see an example.

app.component.ts
accountPages = [
  {
     title: 'Log In',
     url: '/auth/login',
     ionicIcon: 'log-in-outline'
  },
  {
     title: 'Sign Up',
     url: '/auth/signup',
     ionicIcon: 'person-add-outline'
  },
  ... // more pages
]
app.component.html
<ion-list>
  <ion-list-header>
    <ion-label>Account</ion-label>
  </ion-list-header>
  <ion-menu-toggle autoHide="false" *ngFor="let p of accountPages; let i = index">
    <ion-item [routerLink]="p.url">
      <ion-icon slot="start" [name]="p.ionicIcon? p.ionicIcon: ''" [src]="p.customIcon? p.customIcon: ''"></ion-icon>
      <ion-label>
        {{p.title}}
      </ion-label>
    </ion-item>
  </ion-menu-toggle>
</ion-list>

Last updated