Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #23448
What is the current behavior?
Currently,
ion-back-button,NavController.pop(), the hardware back button and the swipe to go back gesture all navigate to the previous view's URL, which pushes a new browser history entry. Pressing the browser's back button after that returns you to the page you just left, and the history keeps growing as you go back and forth.What is the new behavior?
When the previous view is the entry directly behind the current one in browser history, popping now calls
location.back()instead of navigating by URL, so the entry is popped instead of a new one being pushed.To know that,
NavControllerkeeps track of the navigation ids of the history entries the router writes, and each view records the entry it was shown in. If anything makes that unclear (a URL changed outside the router withLocation.go(), a hash change, a canceled or failed navigation that may have left the browser somewhere else), we drop the tracking and fall back to the old behavior rather than guess.Routes with a guard or resolver that would run on the way back also keep navigating by URL. A history navigation that gets canceled leaves the browser on the wrong entry, so I didn't want to risk that.
The stack controller also no longer removes the last view when the router flags a browser back/forward navigation as
replaceUrl, since those don't replace anything and it was dropping views from the tab stacks.Does this introduce a breaking change?
Other information
This only covers popping one view.
pop()withdeep > 1, going back after switching tabs and thedefaultHreffallback still push a new entry like before. ThedefaultHrefcase is what #17752 was about, so that one isn't fixed here.If a
pop()and another navigation start in the same task (e.g., a button with both arouterLinkand(click)="navCtrl.pop()", which the lazy tabs test app has), the pop still wins like it did before. The router only handleslocation.back()after the current task ends, so in that case we navigate by URL instead.Going back with
ion-back-buttonnow leaves forward entries in browser history, which makes an existing bug easier to hit. Angular gives an entry a new navigation id each time the browser lands on it, so after going back twice and then pressing the browser's forward button twice,NavControllerguesses the second forward asbackand resets the stack. The same thing happens onmainwith only the browser's back and forward buttons, so I left it for a separate fix. (This is already an issue tracked as FW-7353, the community issue is #28307)