I have a log in screen that is intro page. After logging in I set the root page to my tabs page. That all works fine. When I log out, I’m trying to reset the root to the login page, but that’s not happening. The login page reappears, but the tabs are still present. When logging back in, another set of tabs stack on top of the old tabs. I can’t figure out how to clear them away.
The only thing that has kinda worked is window.location.reload(); as an alternative to the last line, but that seems a bit hacky. It flashes white they redirects to my login.
I ran into this same thing. Here’s how I fixed it:
In your “IntroPage”, I assume you’re passing in NavController to the constructor and setting this.nav = nav. Instead, pass in IonicApp and use getComponent to get the root nav…
So your @App template probably has a “template” that should look something like this:
@sanjaychavan that’s awesome! thank! but when login again it show the back button at home page! simply mean the the navCtrl is not set to the root page
I think all of these suggestions involving parent and getRootNav() should be avoided.
It is the webapp equivalent of spaghetti.
It is important to isolate aspects of your code, drawing strict boundaries between various spheres of influence. Subpages have no business messing with root navigation, nor should they even know how many parents they have or how they were instantiated. It is impossible to write comprehensive tests for an app component if a bunch of other unrelated pages are messing with its navigation stack.
So when you feel the need to do something like this, stop. Redesign your app so that you don’t need to. You will end up with a much clearer, readable, and testable app as a result.