Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a root page outside of tabs that don't keep the tabs in place?

The flow of my app means that there are no tabs in place until a user logs in. The first page is a full-screen login screen. Once logged in the user is taken to tabs.ts which holds my tabs code.

One of the tabs has a button in that logs users out:

user.ts:

  // Logout
  logout() {    
    // Log the user out
    this.user.logout();

    // Take user to login screen
    this.navCtrl.setRoot(LoginPage);
  }

I thought that setting the root to LoginPage, which isn't part of any tab page, would remove the tabs. Unfortunately not, and the tabs remain. This is really problematic for obvious reasons.

How can I remove the tabs from this point? I feel like I need to potentially grab the tabs instance and destroy it, but that's a guess and I'm struggling to find anything in the docs.

like image 971
Mike Avatar asked Aug 08 '17 14:08

Mike


People also ask

Which of the attributes of ion-tab-button allows the tab to be linked to its webpage?

The ion-tab-button and ion-tab above are linked by the common tab property. The tab property identifies each tab, and it has to be unique within the ion-tabs . It's important to always set the tab property on the ion-tab and ion-tab-button , even if one component is not used.

What are ion-tabs and Ion tab used for?

Tabs are a top level navigation component to implement a tab-based navigation. The component is a container of individual Tab components. The ion-tabs component does not have any styling and works as a router outlet in order to handle navigation.

How do I change the tab name in ionic?

If you just want to change the text that appears as the tab link, then go to src/pages/tabs/tabs. html and in that file change the tabTitle to whatever text you would like to display. For example, when you create new tabs template and you want to change the 'about' tab to 'settings'.


1 Answers

After posting this I found the answer on the Ionic forums.

Effectively, each tab maintains its own navigation stack, which I was aware of but I expected the setRoot to bypass the stack. Logically, it does not.

Instead, you need to call getRootNav().setRoot() on your App.

App is imported from ionic-angular, and then passed to your controller.

A full (albeit truncated) example:

import { Component } from '@angular/core';
import { App } from 'ionic-angular';

@Component({
  selector: 'page-profile',
  templateUrl: 'profile.html'
})
export class ProfilePage {

  constructor(
    private app: App
  ) {

  }

  // Logout
  logout() {
    // Take user to login screen
    this.app.getRootNav().setRoot(LoginPage);
  }

}
like image 186
Mike Avatar answered Sep 27 '22 19:09

Mike