When using tabs in Ionic Vue, the navigation breaks when you switch between tabs if two or more tabs are one or more inner/sibling view deep in their respective navigation stacks.
This might be due to the incorrect use of tabs on my end, but the issue is consistently re-creatable on a fresh Ionic Vue project with tabs.
Steps to re-produce
- Start the app on the first tab.
- Open the first tab’s inner/sibling view.
- Switch to a second tab.
- Open the second tab’s inner/sibling view.
- Switch back to the first tab.
- Use the tab button or a
<ion-back-button>
to navigate back to this tab’s root page. - Switch back to the second tab again.
- Trying to go back to the initial page on this tab, either by tapping the tab button again or using a
<ion-back-button>
, breaks navigation.
This also happens if you have, say 4 or 5 tabs, and switch between them normally like you would any other app if at least two of those tabs are one inner/sibling view deep.
Obviously, this is a pretty strange issue and will probably not occur in a production app often, if ever.
Also, I’ve noticed that if the navigation breaks on a physical device, it sometime causes the app to crash and restart from the splash screen.
I would appreciate any advice or pointers on this if I’m using tabs incorrectly.
StackBlitz
https://stackblitz.com/~/github.com/EA-Wardie/ionic-tabs-vue
Code
TabsPage.vue (generated with ionic start
)
<template>
<ion-page>
<ion-tabs>
<ion-router-outlet></ion-router-outlet>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="tab1" href="/tabs/tab1">
<ion-icon aria-hidden="true" :icon="triangle" />
<ion-label>Tab 1</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab2" href="/tabs/tab2">
<ion-icon aria-hidden="true" :icon="ellipse" />
<ion-label>Tab 2</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab3" href="/tabs/tab3">
<ion-icon aria-hidden="true" :icon="square" />
<ion-label>Tab 3</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</ion-page>
</template>
Tab1Page.vue (generated with minor changes)
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Tab 1</ion-title>
</ion-toolbar>
</ion-header>
<ion-content :fullscreen="true">
<ion-button router-link="/tabs/tab1/view">Go To Inner View</ion-button>
</ion-content>
</ion-page>
</template>
Tab1View.vue (inner view created for tab 1)
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button/>
</ion-buttons>
<ion-title>Inner Tab 1 View</ion-title>
</ion-toolbar>
</ion-header>
<ion-content fullscreen color="light">
Inner Tab 1 View
</ion-content>
</ion-page>
</template>
Tab2Page.vue (generated with minor changes)
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-title>Tab 2</ion-title>
</ion-toolbar>
</ion-header>
<ion-content :fullscreen="true">
<ion-button router-link="/tabs/tab2/view">Go To Inner View</ion-button>
</ion-content>
</ion-page>
</template>
Tab2View.vue (inner view created for tab 2)
<template>
<ion-page>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button/>
</ion-buttons>
<ion-title>Inner Tab 2 View</ion-title>
</ion-toolbar>
</ion-header>
<ion-content fullscreen color="light">
Inner Tab 2 View
</ion-content>
</ion-page>
</template>
index.ts (routes)
const routes: Array<RouteRecordRaw> = [
{
path: '/',
redirect: '/tabs/tab1'
},
{
path: '/tabs/',
component: TabsPage,
children: [
{
path: '',
redirect: '/tabs/tab1'
},
{
path: 'tab1',
component: () => import('@/views/Tab1Page.vue')
},
{
path: 'tab1/view',
component: () => import('@/views/Tab1View.vue'),
},
{
path: 'tab2',
component: () => import('@/views/Tab2Page.vue')
},
{
path: 'tab2/view',
component: () => import('@/views/Tab2View.vue'),
},
{
path: 'tab3',
component: () => import('@/views/Tab3Page.vue')
},
]
}
]