Side Menu

Using side menu in this Ionic 4 template

After you go through the authentication pages and you log in into the app, you will see that there are two ways to navigate into the app pages: using tabs and using the side menu.

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

The code for the side menu can be found in src/app/app.component.html and in src/app/app.component.ts

We use the ion-menu component from Ionic UI Components. Using it is super easy. You can either define the menu items in the markup or in the Component.

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 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.

<ion-list>
<ion-list-header>Forms</ion-list-header>
<ion-menu-toggle auto-hide="false">
<ion-item [routerLink]="['/forms-and-validations']">
<ion-icon slot="start" src="./assets/sample-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"></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',
icon: './assets/sample-icons/side-menu/login.svg'
},
{
title: 'Sign Up',
url: '/auth/signup',
icon: './assets/sample-icons/side-menu/signup.svg'
},
... // more pages
]
app.component.html
<ion-list> <ion-list-header>Account</ion-list-header>
<ion-menu-toggle auto-hide="false" *ngFor="let p of accountPages; let i = index">
<ion-item [routerLink]="p.url">
<ion-icon slot="start" [src]="p.icon"></ion-icon>
<ion-label>
{{p.title}}
</ion-label>
</ion-item>
</ion-menu-toggle>
</ion-list>

‚Äč