I have a tab layout with 5 tabs. When i navigate to the second tab and then to a subpage, navigating back with ion-back-button lands on the first tab. How can i go back to the last selected tab?
Any help much appreciated!
const routes: Routes = [
{ path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
{ path: 'home', loadChildren: './home/home.module#HomePageModule' },
{ path: 'timetable', loadChildren: './timetable/timetable.module#TimetablePageModule' },
{ path: 'artistDetail/:id', loadChildren: './artist-detail/artist-detail.module#ArtistDetailPageModule' },
{ path: 'artist', loadChildren: './artist/artist.module#ArtistPageModule' },
];
Tab routes:
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: '',
redirectTo: '/tabs/(home:home)',
pathMatch: 'full',
},
{
path: 'home',
outlet: 'home',
component: HomePage
},
{
path: 'timetable',
outlet: 'timetable',
component: TimetablePage
},
{
path: 'artist',
outlet: 'artist',
component: ArtistPage
}
]
},
{
path: '',
redirectTo: '/tabs/(home:home)',
pathMatch: 'full'
}
];
Tabs
<ion-tab label="Dashboard" icon="home" href="/tabs/(home:home)">
<ion-router-outlet name="home"></ion-router-outlet>
</ion-tab>
<ion-tab label="Zeitplan" icon="time" href="/tabs/(timetable:timetable)">
<ion-router-outlet name="timetable"></ion-router-outlet>
</ion-tab>
[...]
Tab Page which navigates to subpage of tab with routerLink
<div class="venue-box animated fadeIn fast delay-500ms" *ngFor="let artist of data" routerLink="/artistDetail/{{artist.id}}" [ngStyle]="{'background-image': 'url(' + artist?.imagePath + ')'}">
<div class="box">
<h1>{{artist?.name}}</h1>
<p>{{artist?.subtitle}}</p>
</div>
</div>
Header on Subpage:
<ion-header>
<ion-toolbar color="primary">
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
<ion-title>{{artist}}</ion-title>
</ion-toolbar>
</ion-header>