You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ion-back-button does not work correctly together with angular router navigate option "replaceUrl" (V4) #15181
Describe the Bug
ion-back-button does not work correctly together with angular router replaceUrl option
Steps to Reproduce
if i navigate from "/home" to "/login" and then navigate to "/pageC" by setting:
this.router.navigate(["/pageC"], {replaceUrl:true});
the browser back button correctly take me back to "/home" instead of "/login "
but ion-back-button still take me back to "/login"
Related Code
If you are able to illustrate the bug with an example, please provide a sample application via an online code collaborator such as StackBlitz, or GitHub.
Expected Behavior
ion-back-button should take me back to "/home" instead of "/login " while the angular router option replaceUrl is set to "true"
Additional Context
List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, screenshots, OS if applicable, etc.
Reacted by Asif Rahman, Renaldas, Kevin Kelchen, Antonio Gallo, Igor Janković, Alexander Trakhimenok, Ricard-sans-eau, Michael B and hassan-1993
I am also experiencing this same issue. In doing further investigation, I believe the issue is that when doing a router.navigate with replaceUrl: true, it is not updating the url / fullPath within the StackController of the ion router outlet.
In my scenario my page has child routing, and on enter it sets a default child route programatically. So for example navigating to /home will automatically do a relative navigation to /home/child using replaceUrl: true. Now from here if I navigate to /another-page the back button takes me to /home instead of /home/child which is very similar to the op's issue.
Is there any way I can force the stack in ion router outlet to update the url of the current view?
I have had some success by migrating to the Angular router (not too hard coming from the new NavController that lightly wraps the Angular router and looking at the NavController's methods in order to know what Angular router calls to replace them with). I've also created a custom Angular back button component that just uses Angular's Location.back() when you click it. That's how I'm getting around this issue for now.
Any updates on this issue from the Ionic team? Thanks!
I assume that pressing hardware back button from dashboard, shouldn't take the user to the Login page since I am passing replaceUrl: true. But it doesn't work and pressing back button takes back to login page.
@naveedahmed1 we are also experiencing this similar issue too! Even worse, we are actually using the root navigation direction when navigating to our home page after the login page, which should reset the navigation stack, but the hardware back button still takes the user to the login page, looks like replaceUrl also does not fix that problem.
This issue has been resolved by #17879. I have pushed a nightly build of Ionic, and it would be great if someone could test and provide some feedback. (npm i @ionic/core@dev @ionic/angular@dev)
We appreciate your patience as we worked to fix this issue!
I've tried it out for myself and replaceUrl seems to be working! 🙂
At the same time, as I mentioned in my comment above, { skipLocationChange: true } similarly doesn't work with the ion-back-button.
I thought it was similar enough of an issue that fixing replaceUrl may have also fixed skipLocationChange but that didn't end up being the case. Therefore, perhaps it should be considered a separate issue.
I think the issue has been fixed now, I have tested it on device and it works without any issue.
But now I am having another issue. In my case when user is on Dashboard, pressing device back button should exit the app, but it doesn't, it stays on the dashboard page and does't nothing, even despite of pressing the hardware back button multiple times.
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Activity
daem0ndev commentedon Sep 15, 2018
I am also experiencing this same issue. In doing further investigation, I believe the issue is that when doing a router.navigate with replaceUrl: true, it is not updating the url / fullPath within the StackController of the ion router outlet.
In my scenario my page has child routing, and on enter it sets a default child route programatically. So for example navigating to
/homewill automatically do a relative navigation to/home/childusing replaceUrl: true. Now from here if I navigate to/another-pagethe back button takes me to/homeinstead of/home/childwhich is very similar to the op's issue.Is there any way I can force the stack in ion router outlet to update the url of the current view?
KevinKelchen commentedon Oct 29, 2018
I am experiencing the same issue as well. 🙂
It likewise happens with the
{ skipLocationChange: true }setting where the browser back button honors it while theion-back-buttondoes not.KevinKelchen commentedon Nov 26, 2018
I have had some success by migrating to the Angular router (not too hard coming from the new
NavControllerthat lightly wraps the Angular router and looking at theNavController's methods in order to know what Angular router calls to replace them with). I've also created a custom Angular back button component that just uses Angular'sLocation.back()when you click it. That's how I'm getting around this issue for now.Any updates on this issue from the Ionic team? Thanks!
naveedahmed1 commentedon Jan 13, 2019
Any update on this?
In my case on login page after successful login, I redirect user to dashboard:
this.router.navigateByUrl('/dashboard', { replaceUrl: true });I assume that pressing hardware back button from dashboard, shouldn't take the user to the Login page since I am passing replaceUrl: true. But it doesn't work and pressing back button takes back to login page.
daem0ndev commentedon Jan 13, 2019
@naveedahmed1 we are also experiencing this similar issue too! Even worse, we are actually using the
rootnavigation direction when navigating to our home page after the login page, which should reset the navigation stack, but the hardware back button still takes the user to the login page, looks like replaceUrl also does not fix that problem.naveedahmed1 commentedon Jan 13, 2019
Yes you are right, I also tried
navCtrl.navigateRootbut it doesn't work either.qiluo commentedon Jan 29, 2019
Exact problem on my side. ion-back-button ignored
replaceUrl:truecompletely.I'm on 4.0.0 final
adsonrocha commentedon Jan 30, 2019
Same issue here...
ryaa commentedon Jan 30, 2019
The problem is reproducible on the most recently release 4.0.0.
robingenz commentedon Jan 30, 2019
+1
adsonrocha commentedon Jan 31, 2019
@paulstelzer any news on this? This is critical to a good UX and my team is waiting to launch the app.
1 remaining item
JerryBels commentedon Feb 3, 2019
+1
kkbear1985 commentedon Feb 4, 2019
I believe you can replace state manually in the callback of exit event with location.replacestate , just check this stackoverflow https://stackoverflow.com/questions/38891002/angular-2-replace-history-instead-of-pushing
But anyway, the way I deal with this is just simply do not use backbutton , it is bugged
adsonrocha commentedon Feb 8, 2019
The way I've overcome this issue:
JerryBels commentedon Feb 9, 2019
Nice ! I would add
this.navCtlr.setDirection('back');to the directive in order to properly animate it also :)Jesteban1125 commentedon Mar 6, 2019
I suggest another alternative
Create a new class (CustomNavController) that extends from NavController
Add the CustomNavController class as your NavController to your providers (main module)
Example:
naveedahmed1 commentedon Mar 6, 2019
Should we expect a permanent fix from Ionic team anytime soon?
@manucorporat @paulstelzer I think reliable and robust routing should have higher priority.
liamdebeasi commentedon Mar 29, 2019
Hi there,
This issue has been resolved by #17879. I have pushed a nightly build of Ionic, and it would be great if someone could test and provide some feedback. (
npm i @ionic/core@dev @ionic/angular@dev)We appreciate your patience as we worked to fix this issue!
KevinKelchen commentedon Apr 3, 2019
I've tried it out for myself and
replaceUrlseems to be working! 🙂At the same time, as I mentioned in my comment above,
{ skipLocationChange: true }similarly doesn't work with theion-back-button.I thought it was similar enough of an issue that fixing
replaceUrlmay have also fixedskipLocationChangebut that didn't end up being the case. Therefore, perhaps it should be considered a separate issue.liamdebeasi commentedon Apr 4, 2019
@KevinKelchen,
Ah yes thank you for the reminder! Would you be able to create an issue for it? I think it's worth tracking that separately.
Thanks!
naveedahmed1 commentedon Apr 7, 2019
I think the issue has been fixed now, I have tested it on device and it works without any issue.
But now I am having another issue. In my case when user is on Dashboard, pressing device back button should exit the app, but it doesn't, it stays on the dashboard page and does't nothing, even despite of pressing the hardware back button multiple times.
liamdebeasi commentedon Apr 9, 2019
Hi @naveedahmed1,
This is a known issue. You can follow the Back Button Issue Thread for more info.
Thanks!
ionitron-bot commentedon May 9, 2019
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.