ionic-framework: [Ionic v4-beta.3] Bug navigation between tab page & no page tab - back button redirects to wrong tab

Bug Report

Ionic Info

Ionic:

   ionic (Ionic CLI)          : 4.1.0 (/usr/local/lib/node_modules/ionic)
   Ionic Framework            : @ionic/angular 4.0.0-beta.3
   @angular-devkit/core       : 0.7.0-rc.3
   @angular-devkit/schematics : 0.7.0-rc.3
   @angular/cli               : 6.0.8
   @ionic/ng-toolkit          : 1.0.0
   @ionic/schematics-angular  : 1.0.1

Cordova:

   cordova (Cordova CLI) : 7.1.0
   Cordova Platforms     : ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.0.2, (and 4 other plugins)

System:

   ios-deploy : 1.9.2
   ios-sim    : 6.1.1
   NodeJS     : v10.6.0 (/usr/local/bin/node)
   npm        : 6.4.0
   OS         : macOS High Sierra
   Xcode      : Xcode 9.4.1 Build version 9F2000

Describe the Bug I have an application with a tabs ( 5 pages home, search, map , info and tarif). From the search page i can go on a non-tab page like this this.router.navigate(['station'], { queryParams: station}); On the station page i have a back button to return to the search page <ion-back-button text=""></ion-back-button> The back button disappear at the second time. Here are some additional informations:

tabs.router.module.ts

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: 'home',
        outlet: 'home',
        component: HomePage
      },
      {
        path: 'search',
        outlet: 'search',
        component: SearchPage
      },
      {
        path: 'map',
        outlet: 'map',
        component: MapPage
      },
      {
        path: 'info',
        outlet: 'info',
        component: InfoPage
      },
      {
        path: 'tarif',
        outlet: 'tarif',
        component: TarifPage
      }
    ]
  },
  {
    path: '',
    redirectTo: '/tabs/(home:home)',
    pathMatch: 'full'
  }
];

app-routing.module.ts

const routes: Routes = [
  { path: '', loadChildren: './tabs/tabs.module#TabsPageModule' },
  { path: 'map', loadChildren: './map/map.module#MapPageModule' },
  { path: 'search', loadChildren: './search/search.module#SearchPageModule' },
  { path: 'station', loadChildren: './station/station.module#StationPageModule' },
  { path: 'info', loadChildren: './info/info.module#InfoPageModule' },
  { path: 'tarif', loadChildren: './tarif/tarif.module#TarifPageModule' }
];

i don’t know if it’s my bad or a bug ?

Steps to Reproduce Steps to reproduce the behavior:

  1. Click on tab menu to go to search page
  2. From search page go to station page ( a non-tab page)
  3. Go back to search page with back button
  4. Click on the same station to go on station page
  5. The back button disappear, i can’t go back on search page

Expected Behavior Fix nav when i from a non-tab page

Additional Context I have a log when i go to the station page at the second time ion-router-outlet.js:32 router-outlet destroyed

And i have an another issue, how i can conserve the tab menu on my station page ?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 20
  • Comments: 58 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Let’s make my summarize the issue:

  • You leave the tabs section on tab User with routerDirection="forward"
  • Now you want to go back
  • You will send back to tab 1 (Home) - not to User where you left the tabs

2019-01-15_10-55-14

  • The reason: The url is only tabs, not the last tab page you visited

chrome_2018-12-14_15-06-24

So this route is matching:

      {
        path: '',
        redirectTo: '/tabs/home',
        pathMatch: 'full',
      },

And the user will be redirect to home instead of tabs/user

This is based on https://github.com/lampi87/ionic-bug-test (you have to add the redirect route again to see the issue). This repo has not the redirect route, so the user stays on User where he left the tabs

In tabs.router.module.ts change this:

const routes: Routes = [ { path: 'tabs', component: TabsPage, children: [ ... { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' }

for this (remove /tab1):

{ path: '', redirectTo: '/tabs', pathMatch: 'full' }

This solves the back button of the topbar as the physical of android. It works well for me.

same issue here: router-outlet destroyed

Hi everyone,

I have opened a PR that should resolve this issue: https://github.com/ionic-team/ionic/pull/18005

One of my colleagues will be reviewing it soon, but in the meantime if anyone would like to take a look and provide feedback, that would be great!

We appreciate your patience as we work to resolve this issue 🙂

@bossjon uh ur right 👍🏻 completely forgot about navigation back via swipe gesture… I added this case to my demo.

ion-back-button-tabs fully support swipe gestures now! For the workaround it seemed easiest to disable the gesture for the particular page.

any news on that? I took a look at the ionic-conference app because it’s working there. Interesting implementation…

Removed redirectTo from tabs routes looks like a fix for this issue, but it caused another issue, there’s no route for ''. So I don’t think it’s a real fix

Note that this sample app: https://github.com/kensodemann/test-prolea which I created to demo a different but related issue (#14861) also shows this behavior if the person picking this up needs a sample app to reproduce this.

Hi there,

This issue has been resolved, and I have published a nightly build of Ionic with the fix. You can install it with npm i @ionic/angular@dev.

Please let me know if you are still running into any issues with this.

Thanks!

I solved the problem by navigate with ionic NavController instead of angular router I changed the following line:

this.router.navigateByUrl(url)

to

this.navController.navigateForward(url)

Same here, the router-outlet destroyed issue makes the page transition becomes rude, without animation (at least in ios).

Simple reproduce:

  • Create page with tabs
  • In first tab (say, home tab), create list of items.
  • Set the item’s href to item detail page.
  • Click it, and you’ll be redirected to the detail page.
  • Now refresh browser, you will stay in detail page.
  • Press ion-back-button (with defaultHref). You’ll be moved to home tab.
  • Now from home tab, click on that item again, and the issue will occur.

Update: For my case, this issue is solved by setting routerDirection="forward" to my items in home tab.

Same issue here. Navigating from a subpage backwards lands on the first tab instead the last selected.

More: https://stackoverflow.com/questions/52268092/navigate-back-to-tab-index-with-ionic-4/52268576#52268576

In tabs.router.module.ts change this:

const routes: Routes = [ { path: 'tabs', component: TabsPage, children: [ ... { path: '', redirectTo: '/tabs/tab1', pathMatch: 'full' }

for this (remove /tab1):

{ path: '', redirectTo: '/tabs', pathMatch: 'full' }

This solves the back button of the topbar as the physical of android. It works well for me.

It solves the issue, but the url is the wrong one at the top, it’s the root tab url (/tabs in my case). Also if you tap the current tab, it tries to load the root tab url.

We are having this issue here as well. If I initiate the navigation outside the Tabs router or navigate to a page that is outside of the Tabs router I cannot access the pages nested over the Tabs router.

The only solution that worked for us is to nested all the pages inside the Tabs and hide the ion-tab-bar on the pages I don’t want it to appears.

<ion-tab-bar slot=“bottom” color=“secondary” *ngIf=“tabsLayout”>

Of course, this is far from the ideal solution but it’s a good way to work around this.

No, you don’t have to do this. You can just not use ion-back-button, instead you add a normal button, a back style, and call navCtrl.back() in the click event. Then you get your expectation

<ion-button (click)="navCtrl.back()">
        <ion-icon slot="icon-only" name="arrow-round-back" color="dark"></ion-icon>
</ion-button>

@aftabkhatri Did you even read what @paulstelzer wrote? Without redirect everything works, but what about redirect? When the user goes to the /tabs page, the page is blank. @paulstelzer knows what the issue is.

I think you get confused and you are discussing another issue.

I solved the problem by navigate with ionic NavController instead of angular router I changed the following line:

this.router.navigateByUrl(url)

to

this.navController.navigateForward(url)

Does not work for me

@servrox, The way you did, it works, but we’re talking about pages with no tabs. Like a global page that can be opened anywhere, and you can go back.

We are having this issue here as well. If I initiate the navigation outside the Tabs router or navigate to a page that is outside of the Tabs router I cannot access the pages nested over the Tabs router.

The only solution that worked for us is to nested all the pages inside the Tabs and hide the ion-tab-bar on the pages I don’t want it to appears.

<ion-tab-bar slot=“bottom” color=“secondary” *ngIf=“tabsLayout”>

Of course, this is far from the ideal solution but it’s a good way to work around this.