Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 37 ยท Navigation and Routing

Ionic Side Menu and Navigation Patterns

Add a slide-out menu with ion-menu, control it with menu-toggle and MenuController, combine it with a split pane, and pick the right navigation pattern.

Not every app fits a tab bar. When you have many destinations, or secondary ones like Settings and Help, a side menu (also called a drawer) is the usual answer. Ionic's ion-menu handles the slide animation, the swipe gesture, the backdrop and accessibility. This lesson builds a menu, controls it from code, makes it permanent on big screens with a split pane, and compares navigation patterns.

A basic menu

The menu needs a contentId that matches the id of the main content it pushes or overlays:

HTML
<ion-app>
  <ion-menu contentId="main-content" type="overlay">
    <ion-header>
      <ion-toolbar color="primary"><ion-title>Menu</ion-title></ion-toolbar>
    </ion-header>
    <ion-content>
      <ion-list>
        <ion-menu-toggle autoHide="false">
          <ion-item routerLink="/home" routerDirection="root" lines="none">
            <ion-icon slot="start" name="home"></ion-icon>
            <ion-label>Home</ion-label>
          </ion-item>
          <ion-item routerLink="/settings" routerDirection="root" lines="none">
            <ion-icon slot="start" name="settings"></ion-icon>
            <ion-label>Settings</ion-label>
          </ion-item>
        </ion-menu-toggle>
      </ion-list>
    </ion-content>
  </ion-menu>

  <ion-router-outlet id="main-content"></ion-router-outlet>
</ion-app>

Highlights:

  • type is overlay (menu over content), reveal (content slides aside), or push.
  • ion-menu-toggle closes the menu after an item is tapped. autoHide="false" keeps it visible even in a split pane.
  • Menu destinations are usually roots (routerDirection="root") because they are peer sections, not drill-downs.

Opening the menu

Place a menu button in each page's toolbar:

HTML
<ion-header>
  <ion-toolbar>
    <ion-buttons slot="start">
      <ion-menu-button></ion-menu-button>
    </ion-buttons>
    <ion-title>Home</ion-title>
  </ion-toolbar>
</ion-header>

ion-menu-button shows the hamburger icon and hides itself if the menu is permanently visible. Users can also swipe in from the screen edge. On a page where swiping would collide with another gesture (a map, a slider), disable it:

HTML
<ion-menu contentId="main-content" [swipeGesture]="false">

Controlling the menu from code

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

constructor(private menu: MenuController) {}

async openMenu()  { await this.menu.open('main'); }
async closeMenu() { await this.menu.close('main'); }
async toggle()    { await this.menu.toggle(); }

Give the menu a menuId when you have more than one, for example a start menu and an end menu:

HTML
<ion-menu side="end" menuId="filters" contentId="main-content">...</ion-menu>

In React the same controller is menuController from @ionic/core; in Vue it is menuController too.

Split pane

On tablets and desktop browsers, a menu that is always visible works better than a drawer. ion-split-pane shows the menu next to the content above a width, and behaves as a drawer below it:

HTML
<ion-split-pane contentId="main-content" when="md">
  <ion-menu contentId="main-content">...</ion-menu>
  <ion-router-outlet id="main-content"></ion-router-outlet>
</ion-split-pane>

when takes a breakpoint (xs, sm, md, lg, xl) or any CSS media query string, such as (min-width: 1024px). The menu button disappears automatically when the pane is expanded.

Stand-in: choose drawer or fixed sidebar

The logic that decides the layout is a width test. This runnable stand-in mirrors it and tracks menu state; it models the behaviour, not Ionic's code.

JS Stand-in: split pane decides menu behavior

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Choosing a navigation pattern

flowchart TD
  A["How many top-level sections?"] -->|2 to 5, equal weight| B["Tabs"]
  A -->|6 or more, or settings and help| C["Side menu"]
  A -->|One main flow| D["Stack only, no menu"]
  A -->|Tablet or desktop target| E["Split pane + menu"]

Pick by structure, not by habit.

Real apps combine patterns. A popular layout is tabs for the main sections with a profile screen that has a settings list, or a menu on tablets that turns into tabs on phones. Other patterns to know:

  • Segments (ion-segment) switch between views inside one page, such as "Day / Week / Month".
  • Modals hold self-contained tasks (compose, filter) that end with save or cancel.
  • Stack only suits linear apps with one entry point: onboarding, a checkout flow, a game launcher.

Highlighting the active item

A menu should show where the user is. With the router you can toggle a class:

CSS
ion-item.selected { --background: rgba(var(--ion-color-primary-rgb), 0.12); --color: var(--ion-color-primary); }
TypeScript
// Angular
this.router.events.pipe(filter((e) => e instanceof NavigationEnd))
  .subscribe((e) => (this.current = (e as NavigationEnd).urlAfterRedirects));

The matching logic is plain string work, which you can run here:

JS Stand-in: mark the active menu item

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Accessibility notes

  • The menu button needs a label; ion-menu-button has one, but if you build your own, add aria-label="Open menu".
  • Focus moves into the menu when it opens and returns to the button when it closes; do not remove the button while the menu is open.
  • Do not hide essential actions only in the menu; users may not find it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What must the contentId of ion-menu match?

    contentId ties the menu to the element that slides or is covered.
  2. 2. What does ion-split-pane do?

    Above the configured width the menu stays visible beside the content.
  3. 3. Which direction should menu destinations use?

    Menu items are peer sections, so they replace the stack instead of adding to it.
  4. 4. When are tabs the better pattern than a side menu?

    Tabs suit a few frequently used equal sections.

Summary

  • ion-menu needs a contentId; ion-menu-button opens it, ion-menu-toggle closes it after a tap.
  • Use type overlay, reveal or push, and control it with MenuController.
  • ion-split-pane keeps the menu visible on wide screens.
  • Choose tabs for few equal sections, menus for many, stack-only for flows.
  • Menu items navigate with the root direction and should show the active item.

Next: Route Params, Guards and Page Lifecycle