I am having a little issue with the ion-back-button where if I do a manual route to the login page (e.g. someone clicks ‘logout’) it shows the back button ok but on press sends you back to the member area, which is now not allowed. I guess this makes sense as its just going back in the history, but is there a way to either force the back button path in that instance or remove it all together?
You’re bypassing the Ionic navigation system when you interact directly with the router like that. So one thing you could try is instead injecting NavController and calling its setRoot() function, which should reset the Ionic nav stack (and presumably nuke the back button).
Is that still available in Ionic 4? According to the docs it is (which I’ve found unreliable anyway) but when I import NavController I just get an error that setRoot is not a function.
Actually navigateRoot did work, except that it didn’t transition back to /login, it just went straight there.
Your second example of {replaceUrl: true} didn’t work but this {skipLocationChange: true} seems to do the same as navigateRoot which I think its slightly better in that it looks like NavController is deprecated.
It would be nice to have the transition but this works for now.
Edit: having said that, it seems to stop the URL from changing to the correct location - perhaps not a problem when this is actually compiled into an app?
Thinking about it, it’s probably safe to just have a manual back button on login that always goes to home - its not as nice as just using the ion-back-button but would prevent this issue?
i am also faced same issue, at the end i got the solution
My issue is, my root page is login when i successfully login i am redirecting to home page, when i press back button from home page it is coming back to login page again but i dont want to login page again once it is successfully login i want to remove login page from stack. Finally i got success
here is the solution
code which i am writing below is in login.ts
import {Router, NavigationExtras } from ‘@angular/router’;