Repository navigation
Description
Bug Report
Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.3.1
Ionic Framework : @ionic/angular 4.0.0-beta.15
@angular-devkit/build-angular : 0.8.6
@angular-devkit/schematics : 0.8.6
@angular/cli : 6.2.6
@ionic/angular-toolkit : 1.1.0
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 7.1.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 10 other plugins)
System:
NodeJS : v8.10.0 (C:\Program Files\nodejs\node.exe)
npm : 6.3.0
OS : Windows 10
Describe the Bug
NavController goBack triggers navigation to previous page after using navigateRoot.
The source if this issue is quite obvious.
Currently NavController goBack method has this implementation :
goBack(animated?: boolean) {
this.setIntent(NavIntent.Back, animated);
return this.location.back();
}
It uses Angular Location provider, which allow to navigate using the browser history (its back method will trigger navigation to last URL in history).
The issue is that no check is done against the current stack and that NavController never clear browser history when the current stack is empty.
Therefore any call to NavController goBack (manually, throught IonBackButton or with Android Hardware back button) will trigger navigation to the previous page even if we navigated to the current page using navigateRoot.
Steps to Reproduce
Steps to reproduce the behavior:
- Have at least 2 routes in your application
- Call
this.navController.navigateRootto navigate from route A to route B - Call
this.navController.goBack - Witness the navigation to route A
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
NavController goBack should not trigger navigation to previous page if we used navigateRoot.
Additional Context
After further investigation, NavController stack is not even filled properly.
Indeed, after using navigateRoot the url of the target page is just pushed in the stack, leaving the previous pages urls :
private guessDirection() {
const index = this.stack.indexOf(document.location!.href);
if (index === -1) {
this.stack.push(document.location!.href);
return 1;
} else if (index < this.stack.length - 1) {
this.stack = this.stack.slice(0, index + 1);
return -1;
}
return 0;
}
Activity
[-][4.0.0-beta.15] **NavController** ``goBack`` trigger navigation to the previous page even if we used ``navigateRoot``[/-][+][4.0.0-beta.15] NavController goBack navigate to previous page even after navigateRoot[/+][-][4.0.0-beta.15] NavController goBack navigate to previous page even after navigateRoot[/-][+][4.0.0-beta.15] NavController goBack triggers navigation to previous page even after using navigateRoot[/+][-][4.0.0-beta.15] NavController goBack triggers navigation to previous page even after using navigateRoot[/-][+][4.0.0-beta.15] NavController goBack triggers navigation to previous page after using navigateRoot[/+]TomDemulierChevret commentedon Nov 20, 2018
The issue is still present on beta.16.
[-][4.0.0-beta.15] NavController goBack triggers navigation to previous page after using navigateRoot[/-][+][4.0.0-beta.16] NavController goBack triggers navigation to previous page after using navigateRoot[/+]ambrzz commentedon Nov 23, 2018
same here...
gulullu commentedon Nov 23, 2018
same here +1
AndrewProteo commentedon Nov 28, 2018
same here +1, this should clear the history before i went to root
bryce13950 commentedon Dec 6, 2018
Is this still an issue with the current beta?
GISerWYJ commentedon Dec 8, 2018
@manucorporat the issue still exist in 4.0.0-beta17.0 ,which may cause wrong behavior when pressing android hardware back button. please check this out. :-)
TomDemulierChevret commentedon Dec 14, 2018
This issue is still presnt in
4.0.0-beta.18.moganarangan commentedon Jan 5, 2019
I'm using this version "@ionic/angular": "4.0.0-rc.0"
And this issue still exists.
I believe this is one of the major drawback and this needs to be addressed at first.
Thank you.
qiluo commentedon Jan 8, 2019
same here, compared to previous v3, looks like there's no stack navigation now. It's all browser history
kamleshkoringa commentedon Jan 18, 2019
We have same issue in 4.0.0-rc.1.
Back button showing login page even if setting navigateRoot
feat(angular): add global pop()
feat(angular): add global pop() (#17182)
ionitron-bot commentedon Feb 20, 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.