I'm having trouble to get tabs navigation working properly.
This is my code so far:
App.tsx:
const App: React.FC = () =>
<IonApp>
<IonReactRouter>
<IonRouterOutlet id="main">
<Route exact path="/" render={() => <Redirect to="/home"/>}/>
<Route path="/home" render={(props) => <Home {...props}/>} exact={true}/>
</IonRouterOutlet>
</IonReactRouter>
</IonApp>
)
Home.tsx:
const Home: React.FC<RouteComponentProps> = (props: RouteComponentProps) => (
<IonPage>
<IonTabs>
<IonRouterOutlet id='tabs'>
<Route path='/:tab(myDecks)' render={(props) => <MyDecks {...props} />} exact/>
<Route path='/:tab(explore)' render={(props) => <Explore {...props} />} exact/>
<Redirect from='/home' to='/myDecks'/>
</IonRouterOutlet>
<IonTabBar slot='bottom'>
<IonTabButton tab='myDecks' href='/myDecks'>
<IonLabel>My Decks</IonLabel>
</IonTabButton>
<IonTabButton tab='explore' href='/explore'>
<IonLabel>Explore</IonLabel>
</IonTabButton>
</IonTabBar>
</IonTabs>
</IonPage>
);
MyDecks.tsx:
const MyDecks: React.FunctionComponent<RouteComponentProps> = (props: RouteComponentProps) => {
return <>
<IonHeader>
<IonToolbar>
<IonTitle>My Decks</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent className='ion-padding'>
My Decks
</IonContent>
</>
};
The current behavior is:
- User access /
- User is redirected to /home
- Another redirect to /myDeck, "My Deck" tab selected and URL is good.
- If the user clicks on the "Explore" tab, URL changes, "My Deck" tab is deselected and the "Explore" tab is selected, however, the page content doesn't change.
If I alter the order of the routes inside <IonRouterOutlet>, then the "My Decks" tab is originally selected, and when the user first clicks the "Explore" tab, it renders ok, but never get back to "My Decks" tab.
I also noticed that when refreshing at /myDeck or /explore no content renders at all.