Skip to content

Commit 9c06dc2

Browse files
authored
docs(react): clarify IonTabs behavior with IonPage (#3012)
1 parent af69fb0 commit 9c06dc2

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

docs/react/navigation.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -419,54 +419,56 @@ Let's start by taking a look at our `Tabs` component:
419419

420420
```tsx
421421
import { Redirect, Route } from 'react-router-dom';
422-
import { IonPage, IonIcon, IonLabel, IonRouterOutlet, IonTabBar, IonTabButton, IonTabs } from '@ionic/react';
422+
import { IonIcon, IonLabel, IonRouterOutlet, IonTabBar, IonTabButton, IonTabs } from '@ionic/react';
423423
import { IonReactRouter } from '@ionic/react-router';
424424
import { ellipse, square, triangle } from 'ionicons/icons';
425425
import Tab1 from './pages/Tab1';
426426
import Tab2 from './pages/Tab2';
427427
import Tab3 from './pages/Tab3';
428428

429429
const Tabs: React.FC = () => (
430-
<IonPage>
431-
<IonTabs>
432-
<IonRouterOutlet>
433-
<Redirect exact path="/tabs" to="/tabs/tab1" />
434-
<Route exact path="/tabs/tab1">
435-
<Tab1 />
436-
</Route>
437-
<Route exact path="/tabs/tab2">
438-
<Tab2 />
439-
</Route>
440-
<Route path="/tabs/tab3">
441-
<Tab3 />
442-
</Route>
443-
<Route exact path="/tabs">
444-
<Redirect to="/tabs/tab1" />
445-
</Route>
446-
</IonRouterOutlet>
447-
<IonTabBar slot="bottom">
448-
<IonTabButton tab="tab1" href="/tabs/tab1">
449-
<IonIcon icon={triangle} />
450-
<IonLabel>Tab 1</IonLabel>
451-
</IonTabButton>
452-
<IonTabButton tab="tab2" href="/tabs/tab2">
453-
<IonIcon icon={ellipse} />
454-
<IonLabel>Tab 2</IonLabel>
455-
</IonTabButton>
456-
<IonTabButton tab="tab3" href="/tabs/tab3">
457-
<IonIcon icon={square} />
458-
<IonLabel>Tab 3</IonLabel>
459-
</IonTabButton>
460-
</IonTabBar>
461-
</IonTabs>
462-
</IonPage>
430+
<IonTabs>
431+
<IonRouterOutlet>
432+
<Redirect exact path="/tabs" to="/tabs/tab1" />
433+
<Route exact path="/tabs/tab1">
434+
<Tab1 />
435+
</Route>
436+
<Route exact path="/tabs/tab2">
437+
<Tab2 />
438+
</Route>
439+
<Route path="/tabs/tab3">
440+
<Tab3 />
441+
</Route>
442+
<Route exact path="/tabs">
443+
<Redirect to="/tabs/tab1" />
444+
</Route>
445+
</IonRouterOutlet>
446+
<IonTabBar slot="bottom">
447+
<IonTabButton tab="tab1" href="/tabs/tab1">
448+
<IonIcon icon={triangle} />
449+
<IonLabel>Tab 1</IonLabel>
450+
</IonTabButton>
451+
<IonTabButton tab="tab2" href="/tabs/tab2">
452+
<IonIcon icon={ellipse} />
453+
<IonLabel>Tab 2</IonLabel>
454+
</IonTabButton>
455+
<IonTabButton tab="tab3" href="/tabs/tab3">
456+
<IonIcon icon={square} />
457+
<IonLabel>Tab 3</IonLabel>
458+
</IonTabButton>
459+
</IonTabBar>
460+
</IonTabs>
463461
);
464462

465463
export default Tabs;
466464
```
467465

468466
If you have worked with Ionic Framework before, this should feel familiar. We create an `IonTabs` component and provide an `IonTabBar`. The `IonTabBar` provides `IonTabButton` components, each with a `tab` property that is associated with its corresponding tab in the router config. We also provide an `IonRouterOutlet` to give `IonTabs` an outlet to render the different tab views in.
469467

468+
:::tip
469+
`IonTabs` renders an `IonPage` for you, so you do not need to add `IonPage` manually here.
470+
:::
471+
470472
### How Tabs in Ionic Work
471473

472474
Each tab in Ionic is treated as an individual navigation stack. This means if you have three tabs in your application, each tab has its own navigation stack. Within each stack you can navigate forwards (push a view) and backwards (pop a view).

0 commit comments

Comments
 (0)