This tutorial is out of date and no longer maintained.
Warning: Since publication, Ionic 4 is no longer the latest version. The ionic
has been deprecated and @ionic/cli
is the preferred method for installing the Ionic CLI.
Tabs! They’re a stable way to manage multiple views in modern applications. In this article, we’ll be looking at how to use Tabs with Ionic 4.
We’ll be using Ionic and Angular for this example, but as Ionic components are standard Web Components, the process is similar across frameworks.
Note: Whilst you can start a new Ionic project with the tabs
template, this article looks at integrating tabs
to an existing project instead.
Let’s first initialize a new project using the Ionic CLI.
First, install the Ionic CLI, if you don’t have it installed already:
Then, create a new project:
Then, change into the new project directory:
Run the project in the browser:
We’ve now got an Ionic 4 and Angular project up and running. Let’s generate some new pages to provide the foundation for our tab system.
Generate the main page that serves the tabs:
Generate individual tabs:
At this stage, we can go ahead and add any content we’d like to each tab. For this example, we’ll make the following assumptions:
For each tab, update the HTML to reflect this:
Our main tabs.page.html
houses each of the tabs and we can add an ion-tabs
and ion-tab-bar
with a reference to our tab
by route:
Now we can set up routing for our tabs
page. Let’s set the tabs
page to be the default route inside of our app-routing.module.ts
:
When the user hits the default route, we’ll need to handle which tab to be shown. Create a new file named tabs-routing.module.ts
inside of the tabs
folder with the following content:
As you can see, we’re exporting a module that contains the route configuration for our tabs. The path
(i.e., tab1
) should correspond to the ion-tab-button
as seen inside of our tabs.page.html
:
Finally, we’ll need to import this module inside of our tabs.module.ts
:
We should now be able to navigate through our application using the tab structure!
In this tutorial, you learned how to use Tabs with Ionic 4.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!