refactor(router): Adjust push/replace behavior to account for navigation API timing issues

There is a bug (?) in all browsers where the timing of the entry change
is delayed when a navigation is initiated by a click on a link via user
interaction. In this case, we need to ensure we do a 'push' navigation
rather than a 'replace'.
Programatically doing element.click() does not reproduce
this behavior, so adding a test for this is difficult (would require
webdriver).
This commit is contained in:
Andrew Scott 2025-12-03 12:32:44 -08:00 committed by Alex Rickabaugh
parent 5fa407530c
commit 37598cf6fe

View file

@ -221,6 +221,13 @@ export class NavigationStateManager extends StateManager {
};
const info: NavigationInfo = {ɵrouterInfo: {intercept: true}};
// https://issues.chromium.org/issues/460137775 - Bug in all browsers where URL might actually not be updated
// by the time we get here. replaceUrl was set to true in the Router when navigating to sync with the browser
// because it assumes the URL is already committed. In this scenario, we need to go back to 'push' behavior
// because it was not yet been committed and we should not replace the current entry.
if (!this.navigation.transition && this.currentNavigation.navigationEvent) {
transition.extras.replaceUrl = false;
}
// Determine if this should be a 'push' or 'replace' history operation.
const history =