Logout Button Does Not Work After Logging Back In


#1

I have a button that performs a logout on various views within my Tabs view container. The logout button runs the following code and works properly:

logout(){
    this.app.getRootNav().setRoot(Login);
}

However when I log back into my application and then click the logout button, the function gets called but I does not set the root nav back to Login.

The login function sets the root to Tabs.


#2

Can you try this?

add viewchild and nav

import { ViewChild } from '@angular/core';
import { Nav } from 'ionic-angular';

define nav:

export class MyApp {
    @ViewChild(Nav) nav: Nav; 

instead of

this.app.getRootNav().setRoot(Login);

try to use this:

this.nav.setRoot(Login);


#3

I get this error:

Error in ./Home class Home - caused by: Cannot read property 'setRoot' of undefined


#4

Your logout code are in your Home class?
I think you have to do this in your root class app.component.ts


#5

How do I call that method from another class?


#6

Here’s how I deal with this concept.


#7

I did that and it worked, but after setting root, logging back in again, and resetting the root after clicking the logout button it does not set the root back to the login page.