ionic-framework: Setting a tabs page as root does not load the first root page

Ionic version: (check one with “x”) [x] 3.x

I’m submitting a … (check one with “x”) [x] bug report

Current behavior: Opening a tabs page by setting it as the root page does not open the first tabs page. It only replaces the tabs bar.

Expected behavior: Opening a tabs page by setting it as the root page will open the selected tabs page and also load its first tab page.

In other words: When clicking on a main menu button, I expect not only the tabs bar to change but also to load the first tab from that tab bar.

Steps to reproduce:

  1. Open a terminal.
  2. git clone https://github.com/Eraldo/tabsIssue.git
  3. cd tabsIssue
  4. ionic serve
  5. Press ENTER to install the dependencies. => Wait until install finishes and your browser opens http://localhost:8100/
  6. Click on “Toggle Menu” button.
  7. Click on “Tabs2” button. => url is now: http://localhost:8100/#/tabs2/first2/first2
  8. Click on “Menu” button (three lines top left corner).
  9. Click on “Tabs” button. => url is now: http://localhost:8100/#/tabs/first/first2 The page from the previous tabs page (First2Page) is still open! I expected FirstPage to be open. In other words I would have expected http://localhost:8100/#/tabs/first/first

Related code: https://github.com/Eraldo/tabsIssue

Other information: I have also created a video demoing the issue in another project: tabsissue 2018-08-02

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

cli packages: (/Users/eraldo/inbox/temp/tabsIssue/node_modules)

    @ionic/cli-plugin-ionic-angular : 1.4.1
    @ionic/cli-utils                : 1.7.0
    ionic (Ionic CLI)               : 3.7.0

local packages:

    @ionic/app-scripts : 2.1.3
    Ionic Framework    : ionic-angular 3.6.0

System:

    Android SDK Tools : 26.0.2
    Node              : v8.2.1
    OS                : macOS Sierra
    Xcode             : Xcode 8.0 Build version 8A218a 
    npm               : 5.3.0 

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 2
  • Comments: 47 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Good night, a solution I found to insert the code in TabsPage:

	ionViewWillEnter() {
		this.tabRef.select(0);
	}

	ionViewDidEnter() {
		this.tabRef.select(0);
	}

Full version in my case

import { Component,ViewChild } from '@angular/core';
import { IonicPage, NavController, Tabs } from 'ionic-angular';

@IonicPage({
  priority: 'high', segment: 'tab'
})
@Component({
  selector: 'page-tab',
  templateUrl: 'tab.html'
})
export class TabPage {

	@ViewChild('myTab') tabRef: Tabs;

	TabPage1Root = 'TabPage1Page'
	TabPage2Root = 'TabPage2Page'
	TabPage3Root = 'TabPage3Page'


	constructor(public navCtrl: NavController) {

	}

	ionViewWillEnter() {
		this.tabRef.select(0);
	}

	ionViewDidEnter() {
		this.tabRef.select(0);
	}


}

@kensodemann You can find the example repository here (it is based on the ionic2-starter-tabs upgraded to the ionic-angular and ionic-app-scripts nightly version). npm install, ionic serve and then watch. The tabs are switched every 7.5 seconds.

While putting the repo together I noticed that the underlying problem is the naming of the ts-class (and module) of the Tabs component. Naming it tabs.ts works just fine but re-naming it to e.g. TabsContainer.ts creates the problem. I guess this is because the name is used for generating the DeepLink config/the URL.

With tabs.ts after switching the tabs for the first time the the URL is: http://localhost:8100/#/tabs/contact/contact which is correct.

With TabsContainer.ts after switching the tabs for the first time the URL is: http://localhost:8100/#/TabsContainer/contact/about which is incorrect.

I can confirm that the workaround provided by @kensodemann works for me. I tried switching between different versions of ionic-angular mentioned here and at other places without any result. The only thing that fixed the problem for now is

@IonicPage({ priority: 'high', segment: 'tabs' })

In my case it seems to work as expected but it’s too early to say for sure. Thanks.

3.7 nightly builds works for me too. Any Info on when this will be included in a regular release?

Thanks for opening an issue with us, we will look into this.

Using 3.9.2 and still don’t works. Using priority going against lazy loading?, I’m confused.

+1

Is there any info yet on when this will be included in a regular release?

I can confirm that it works with the 3.7 nightly build. I am using 3.8 as well and there it does not work as you mentioned. Thank you @ajonp for pointing that out.

@danbucholtz 3.7.1-201710201922 makes this work…3.8.0 will not work.

You can work around this via the following code in TabsContainer.ts:

@IonicPage({ priority: 'high', segment: 'tabs' })

This bug is sufficiently different from the originally reported issue to justify its own issue if you would like to open one.

@DavidStrausz - actually, not really re-checking this issue so much as trying to see if some other issue is a duplicate of this that could be fixed via the not-yet-released nightly. I’ll have a quick look when I get a chance, though.

@HiranHabiff Thanks for your workaround, it solved my issue.

Update: No this does not work, returning back to nightly. @danbucholtz any chance someone can work through this with me?

I want to upgrade to 3.9.2, but it still breaks tabs, I am sitting at 3.7.1-201710201922 currently.

I am using @gatsinski / @kensodemann solution with

@IonicPage({
  priority: 'high'
})

I can confirm this works so far in my testing.

Hello,

This issue is fixed. Can you try it out and let me know if the issue still exists?

npm install ionic-angular@3.7.1-201710060319

Thanks, Dan