1

I have the following Tabs configured in my project:

tabs.html

<ion-tabs  tabsPlacement="bottom" [selectedIndex]="0">
    <ion-tab [root]="tab1Root" tabTitle="Home" tabIcon="pulse"></ion-tab>
    <ion-tab [root]="tab2Root" tabTitle="About" tabIcon="information"></ion-tab>
</ion-tabs>

When in the "Home" page (tab1Root), there is a button to change the Root Page to a "Home v2" page.

home.html

<ion-content class="has-header" padding>
    <div padding style="text-align: center;">
        <h1>Home v1</h1>
        <ion-button button (click)="setRootTab1ToHome2()">
            Set Root of TAB1 to Home v2
        </ion-button>
     </div>
</ion-content>

home.ts

import { NavController } from 'ionic-angular/index';
import { Home2Page } from 'home2.ts'
import { Component } from "@angular/core";

@Component({
  templateUrl:"home.html"
})
export class HomePage {
    constructor(private nav: NavController) {

    }

    setRootTab1ToHome2() {
      this.nav.setRoot(Home2Page);
    }
}

If the TAB1 root page is changed by clicking the available button and then I change to the TAB "About" and change back to the TAB "Home", I will see the Page "Home v2" instead of "Home". BUT, if I click twice on the TAB "Home" it will get back to Page "Home".

How can I restore TAB "Home" root Page to "Home v1" instead of "Home v2" when changing from Tab to Tab? Like the behavior of clicking twice on TAB "Home", but with 1 click only.

Please check the project in the Plunker: https://plnkr.co/F5hAvypKxb9mhQDm3SDw

stronggod
  • 11
  • 1
  • 2
  • why not push home 2 instead of set root? then you can simply pop it – Suraj Rao Apr 20 '17 at 11:11
  • 1
    Refer this link https://alexdisler.com/2016/04/15/remove-page-modal-from-navigation-stack-ionic-2/ – hrdkisback Apr 20 '17 at 11:15
  • Instead `this.nav.setRoot(Home2Page);` try doing `this.tab1Root = Home2Page;` – Sagar Kulkarni Apr 20 '17 at 11:17
  • The reason behind this is, in TAB1 I want to have 2 different Root pages (List view, Map View). Within TAB1 if the user starts navigating from List View and then goes back to the begining (like close navigation button), it gets back to the List View, if starting from Map View it gets back to Map View. But whenever changing TABs and going back to TAB1, I want to force List View as starting point, independent of the Root page it was there before. Does this make sense or should I approach it in a different way? Thanks – stronggod Apr 20 '17 at 16:45
  • @stronggod how does the tabs appear, I don't see you including the tabs.html anywhere – johnny 5 Jul 06 '17 at 04:56

0 Answers0