bug: IonTabs needs a IonTabBar
See original GitHub issueBug Report
Ionic version:
[ ] 4.x [x] 5.x React
Current behavior: Conditionally rendering IonTabBar throws error.
Expected behavior: As commented in the error caller, the error is unnecessary and should be removed.
Location: /IonTabs.tsx:100
if (!tabBar) {
// TODO, this is not required
throw new Error('IonTabs needs a IonTabBar');
}
Steps to reproduce:
- Create a project with IonTabs and React,
- Comment out the IonTabBar.
Related code: Example conditional renderer:
const showTabNav = false;
...
<IonTabs>
<IonRouterOutlet>
...
</IonRouterOutlet>
{showTabNav && (
<IonTabBar slot="bottom">
<IonTabButton tab="tab1" href="/tab1">
<IonIcon icon={mapOutline} />
<IonLabel>Explore</IonLabel>
</IonTabButton>
<IonTabButton tab="tab2" href="/tab2">
<IonIcon icon={homeOutline} />
<IonLabel>Deals</IonLabel>
</IonTabButton>
<IonTabButton tab="tab3" href="/tab3">
<IonIcon icon={walletOutline} />
<IonLabel>Wallet</IonLabel>
</IonTabButton>
</IonTabBar>
)}
</IonTabs>
Other information: N/A
Ionic info: N/A
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:5
Top Results From Across the Web
bug: IonTabs needs a IonTabBar · Issue #21541 · ionic- ...
Current behavior: Conditionally rendering IonTabBar throws error. Expected behavior: As commented in the error caller, the error is unnecessary ...
Read more >React + Ionic 5: Tab navigation problems
According to the React Tabs starter template you have to nest the IonRouterOutlet inside of IonTabs , which is nested in IonReactRouter ....
Read more >Hiding Tab Bar for certain routes - Ionic Forum
I have no way of conditionally rendering it as any time the component is not rendered I get the error Error: IonTabs needs...
Read more >How to mix Tabs and non-tab pages in Ionic React? : r/ionic
I'm looking to have a login page that's just a plain form as the starting point of the app, and once a user...
Read more >CODEBEAT - Automated code review for mobile and web
packages/react/src/components/navigation/IonTabs.tsx ... import { IonTabBar } from './IonTabBar' ; ... throw new Error( 'IonTabs needs a IonTabBar' );.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I also got this error when I tried to move my
<IonTabBar>
into a component and call that component in the same location.For example, based on the related code above:
And then the AppTabBar component:
@ptmkenny
The problem is that the IonTabs component checks if at least one it’s direct children is type of IonTabBar (see https://github.com/ionic-team/ionic-framework/blob/v5.9.1/packages/react/src/components/navigation/IonTabs.tsx#L131-L138)
Workaround is to create Tab wrapper component which includes both IonTabs and IonTabBar
Usage: