@@ -101,7 +101,7 @@ function isSamePageWithHash(absoluteHref: string): boolean {
101
101
return hashIndex > - 1 && location . href . replace ( location . hash , '' ) === absoluteHref . substring ( 0 , hashIndex ) ;
102
102
}
103
103
104
- function performScrollToElementOnTheSamePage ( absoluteHref : string , replace : boolean , state : string | undefined = undefined ) : void {
104
+ function performScrollToElementOnTheSamePage ( absoluteHref : string , replace : boolean , state : string | undefined = undefined ) : void {
105
105
saveToBrowserHistory ( absoluteHref , replace , state ) ;
106
106
107
107
const hashIndex = absoluteHref . indexOf ( '#' ) ;
@@ -158,19 +158,23 @@ function navigateToCore(uri: string, options: NavigationOptions, skipLocationCha
158
158
}
159
159
160
160
function performExternalNavigation ( uri : string , replace : boolean ) {
161
- if ( location . href === uri ) {
162
- // If you're already on this URL, you can't append another copy of it to the history stack,
163
- // so we can ignore the 'replace' flag. However, reloading the same URL you're already on
164
- // requires special handling to avoid triggering browser-specific behavior issues.
165
- // For details about what this fixes and why, see https://github.com/dotnet/aspnetcore/pull/10839
166
- const temporaryUri = uri + '?' ;
167
- history . replaceState ( null , '' , temporaryUri ) ;
168
- location . replace ( uri ) ;
169
- } else if ( replace ) {
170
- location . replace ( uri ) ;
171
- } else {
172
- location . href = uri ;
173
- }
161
+ // If we are navigating to an external URI, defer setting the URL so that we can
162
+ // complete the current navigation operation if the request comes from .NET.
163
+ setTimeout ( ( ) => {
164
+ if ( location . href === uri ) {
165
+ // If you're already on this URL, you can't append another copy of it to the history stack,
166
+ // so we can ignore the 'replace' flag. However, reloading the same URL you're already on
167
+ // requires special handling to avoid triggering browser-specific behavior issues.
168
+ // For details about what this fixes and why, see https://github.com/dotnet/aspnetcore/pull/10839
169
+ const temporaryUri = uri + '?' ;
170
+ history . replaceState ( null , '' , temporaryUri ) ;
171
+ location . replace ( uri ) ;
172
+ } else if ( replace ) {
173
+ location . replace ( uri ) ;
174
+ } else {
175
+ location . href = uri ;
176
+ }
177
+ } , 0 ) ;
174
178
}
175
179
176
180
async function performInternalNavigation ( absoluteInternalHref : string , interceptedLink : boolean , replace : boolean , state : string | undefined = undefined , skipLocationChangingCallback = false ) {
0 commit comments