Hello, I’m having a navigation issue with my app and I can’t figure how to fix it. I’ve been looking for a solution in this forum with no luck. Here is the issue:
I have an app which has a log in. After you successfully log in, it redirects you to a tabs page.
My question is: how is it possible to get to the login page again?
When I hit logout, it, among other stuff should redirect you to the root page, this.navCtrl.popToRoot ();. My problem is that the tabs gets blank (the tabs doesn’t disappear) and I am no able to do any more stuff. I’d like this to redirect me to the login page. Any recommendations?
I don’t understand it very good. I’m setting those three tabs to the root page of each tab. But when I run the command this.navCtrl.popToRoot (); it turns blank.
import { App } from 'ionic-angular'; // add this library.
constructor (
public app: App // initialize it.
) {}
logut () { // and in the function,
this.authServ.logout (); // this is a function to logout from the server
const root = this.app.getRootNav (); // in this line, you have to declare a root, which is the app's root
root.popToRoot (); // here you go to the root.
}
Hope it works for you as well, if not, maybe I forgot something that I can’t remember now. Hope it does, thou.
Thank you very much for you (quick) answer.
But it still doesn’t work… I still see the Tabs.
If you find another line of code… or if someone else has solved the problem…
It should work. I’ve seen my code and there’s no extra code besides that.
Could you share some of your work? Like how are you calling the tabs, your whole app.component, and everything you think that could help me in order to help you.
Do you have errors with my code? What is the behavior?
If you’re not wedded to using pop, here’s how I handle this situation. I have a service that exposes an authentication notifier which is a ReplaySubject<boolean> with a stack depth of 1. In the platform.ready stanza of the app component’s constructor, I subscribe to it and change the app’s root page like so:
Now from anywhere else in the app, we can inject the service that provides the authentication notifier, and call next(true) on it to say “the user is now authenticated (they logged in successfully)” or next(false) to say “no longer authenticated (logged out, session timed out, whatever)”. Nobody has to mess around with NavControllers at all.
@RaulGM
I have to mention that I still use the beta 11 version (because the build is way faster). I suspect it comes from there. So I will freeze this problem for the moment and wait the migration to see if the problem persists.
@rapropos
Thank you for your valuable advise. It could definitively be a way to solve this.