[Ionic 4] Remove page from navigation (Router / NavController)

Hi, I’m using both methods when navigating, this one when I need to pass parameters:

this.router.navigate(['categories/', categoryId], { queryParams: { title: name } });

And this one when not:

this.navCtrl.navigateForward('home');

My App logic is something like this (arrows define the allowed direction of navigation):
Login > Home >< Categories
So when the user goes to Home I block going back to Login by closing the app.

The problem here is that the user can log out, and the app navigates to Login again. In this step, if the user has been logged in, and then used the logout, the Login page is reused and its constructor is not called again.

Is there any way to remove this view from history navigation and force rebuilding it for calling the constructor? I’m currently going to Login again using navigateForward and I emulate the behaviour that I expect putting my code in ionViewDidEnter.

I’m using:

    "@ionic/angular": "^4.0.0-beta.12",
    "ionic": "^4.1.2",

Thanks in advance.

I’m facing similar problem and can’t seem to find a way to go around this.

When the user opens the app first time, go to login, after login navigate to dashboard, but when the back button is pressed it show login again. Can’t find a way to remove this page after login.

Another thing is that placing an if condition on app.component.ts to show login if not logged in, shows the dashboard for a second and then the login page. If I make the login page the default page, when the user is in dashboard and hits back button it show login again.

This is a freaking nightmare

Same here. Trying to find alterante of navcontroller pop method for router

I am also stuck on this

You didn’t write how you do that. anyway, I understand that you don’t want to allow the user to see the login page once they are logged in and you want to show the login page if the user has been logged out.
If thats right, I do it in my App this way and this works well:

in my login I have the ionViewWillEnter() (you can read about the lifecycle function if you’re interessted) function. in this one i check the localstorage value. if it has been set and the value is “1” then I send the user with router to “home” page. if not it shows the login page.
And my logout deletes the localstorage value.

hope this will help you

Have a look at Angular guards…