Skip to content
Tutorials Center
My learning

Topics

Lesson 13 of 37 ยท Navigation and Routing

Ionic Tab Navigation with ion-tabs

Build tab-based apps with ion-tabs and ion-tab-bar: nested routes, one stack per tab, badges, hiding the bar on detail pages and tab state preservation.

A bottom tab bar is the most common navigation pattern on phones: three to five top-level sections, always one tap away. Ionic's ion-tabs builds it and, importantly, gives each tab its own navigation stack. That means you can drill into a detail page inside one tab, switch to another tab, return, and still be on that detail page. This lesson shows the structure, the routing rules and the common pitfalls.

When to use tabs

Use tabs for peer sections the user switches between often: Feed, Search, Messages, Profile. Do not use them for steps in a flow or for more than five items. If you have more, use a side menu (next lessons) or a "More" tab.

The structure

HTML
<ion-tabs>
  <ion-router-outlet></ion-router-outlet>

  <ion-tab-bar slot="bottom">
    <ion-tab-button tab="feed" href="/tabs/feed">
      <ion-icon name="newspaper"></ion-icon>
      <ion-label>Feed</ion-label>
    </ion-tab-button>
    <ion-tab-button tab="search" href="/tabs/search">
      <ion-icon name="search"></ion-icon>
      <ion-label>Search</ion-label>
    </ion-tab-button>
    <ion-tab-button tab="profile" href="/tabs/profile">
      <ion-icon name="person"></ion-icon>
      <ion-label>Profile</ion-label>
      <ion-badge color="danger">2</ion-badge>
    </ion-tab-button>
  </ion-tab-bar>
</ion-tabs>

Three things to notice:

  • ion-tabs contains an ion-router-outlet and an ion-tab-bar.
  • Every ion-tab-button has a tab name, which must match a route child path, and an href for the URL.
  • slot="bottom" puts the bar at the bottom; slot="top" is also possible and is common on tablets.

Routes for tabs

The tabs component is itself a route, and each tab is a child route:

TypeScript
// Angular
export const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      { path: 'feed', loadComponent: () => import('./feed/feed.page').then((m) => m.FeedPage) },
      { path: 'search', loadComponent: () => import('./search/search.page').then((m) => m.SearchPage) },
      { path: 'profile', loadComponent: () => import('./profile/profile.page').then((m) => m.ProfilePage) },
      { path: '', redirectTo: 'feed', pathMatch: 'full' },
    ],
  },
  { path: '', redirectTo: 'tabs/feed', pathMatch: 'full' },
];
JSX
// React: IonTabs contains an IonRouterOutlet
<IonReactRouter>
  <IonTabs>
    <IonRouterOutlet>
      <Route exact path="/tabs/feed" component={Feed} />
      <Route exact path="/tabs/search" component={Search} />
      <Route exact path="/tabs/profile" component={Profile} />
      <Route exact path="/"><Redirect to="/tabs/feed" /></Route>
    </IonRouterOutlet>
    <IonTabBar slot="bottom">
      <IonTabButton tab="feed" href="/tabs/feed">
        <IonIcon icon={newspaper} /><IonLabel>Feed</IonLabel>
      </IonTabButton>
      {/* ...other buttons */}
    </IonTabBar>
  </IonTabs>
</IonReactRouter>
TypeScript
// Vue: parent route with children
{
  path: '/tabs/',
  component: TabsPage,
  children: [
    { path: '', redirect: '/tabs/feed' },
    { path: 'feed', component: () => import('@/views/FeedPage.vue') },
    { path: 'search', component: () => import('@/views/SearchPage.vue') },
  ],
}

One stack per tab

If the user opens /tabs/feed, then /tabs/feed/post/7, switches to Search, then taps Feed again, they land on the post, not on the feed root. Tapping the active tab button again pops back to that tab's root. This matches iOS conventions. Nested detail routes should live under the tab's path:

TEXT
/tabs/feed
/tabs/feed/post/7        <- stays inside the Feed tab stack
/tabs/search
/tabs/search/results/js
flowchart TD
  T["Tab bar"] --> F["Feed stack: feed > post 7"]
  T --> S["Search stack: search"]
  T --> P["Profile stack: profile > settings"]

Three independent stacks share one tab bar.

Stand-in: independent stacks per tab

The model below is runnable. Each tab owns a stack, selecting a tab changes the active one, and tapping the active tab resets its stack to the root.

JS Stand-in: tabs with one stack each

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

No output.

Hiding the tab bar on detail pages

Because ion-tabs wraps the whole router outlet, the bar remains visible on detail pages by default. That is correct for iOS-style navigation, but sometimes you want a full-screen page (a photo viewer, a compose screen). Options:

  • Show those screens in a modal; the modal covers the tab bar.
  • Place the route outside the tabs route so it renders without the bar. You lose the per-tab stack but gain the full screen.
  • Hide the bar conditionally with a class or *ngIf driven by the current route.
CSS
ion-tab-bar.hidden { display: none; }

Badges and active styling

HTML
<ion-tab-button tab="inbox" href="/tabs/inbox">
  <ion-icon name="mail"></ion-icon>
  <ion-label>Inbox</ion-label>
  <ion-badge>{{ unread }}</ion-badge>
</ion-tab-button>

The selected tab receives the class tab-selected and the selected attribute. Customise its colour with a variable:

CSS
ion-tab-button { --color-selected: var(--ion-color-primary); }
ion-tab-bar { --background: var(--ion-color-step-50); }

Run a tiny logic check for the badge you display:

JS Stand-in: unread badge rules

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

No output.

Common pitfalls

  • The tab button's tab value does not match any child route: the tab shows nothing.
  • A route placed outside the tabs parent loses the bar and the per-tab stack.
  • In React, an IonTabs outlet must list all tab routes inside IonRouterOutlet.
  • Too many tabs: keep to five at most.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does each tab have in Ionic?

    Every tab keeps a separate stack, so you can return to where you were in that tab.
  2. 2. What happens when you tap the already-active tab button?

    Re-selecting the active tab resets its stack to the root, the iOS convention.
  3. 3. How can a detail page cover the tab bar?

    Modals overlay everything, and routes outside ion-tabs render without the bar.
  4. 4. Roughly how many tabs should a bar hold at most?

    More than five makes targets too small; use a menu instead.

Summary

  • ion-tabs = ion-router-outlet + ion-tab-bar with buttons whose tab matches child routes.
  • Each tab has its own stack; reselecting the active tab pops to root.
  • Nest detail routes under the tab path to keep the bar and the stack.
  • Hide the bar with modals or routes outside the tabs parent.
  • Keep to five tabs or fewer.

Next: Side Menu and Navigation Patterns