Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default tab in ionic2

Tags:

ionic2

On my login page I am using this.nav.setRoot(TabsPage); to navigate to the 'main app'. However, this makes the first tab the default page. On the other hand, if i use this.nav.setRoot(HomePage); I get the correct page but am missing the tabs. How do I set the default tab on page switch?

like image 749
Andreas Avatar asked Aug 05 '16 18:08

Andreas


People also ask

How do you change tabs in ionic?

All tabs can be changed by setting the value of tabsLayout on the <ion-tabs> element, or in your app's config. For example, this is useful if you want to show tabs with a title only on Android, but show icons and a title for iOS.

How do you make an ionic tab?

Simple tabs menu can be created by using <ion-tabs> and <ion-tab-bar> component.

How do you create tabs in ionic 5?

Adding Tabs Bar in Ionic Application The tab navigation is created by adding the ion-tabs having ion-tab-bar inside it which creates a tab bar on position defined in the slot property. Each tab button is created using the ion-tab-button with tab property which is the path of tab page resulting navigation.

What is the ionic directive that can be used for creating a tab bar?

Answer. Answer: Tabs Directives First, the main directive that wraps everything related to the tabbed interface.


1 Answers

After further googling, I found the solution in the ionic2 documents. If anyone else in the future is wondering the same thing, the solution is to add selectedIndex="X" to the <ion-tabs> tag. (http://ionicframework.com/docs/v2/api/components/tabs/Tabs/)

UPDATE for clarity: your code will look like this for selecting the 3rd tab:

<ion-tabs selectedIndex="2">

and like this fore selecting the 2nd tab:

<ion-tabs selectedIndex="1">

like image 132
Andreas Avatar answered Oct 20 '22 15:10

Andreas