diff --git a/src/Microsoft.AspNetCore.Blazor.Browser/Routing/UriHelper.cs b/src/Microsoft.AspNetCore.Blazor.Browser/Routing/UriHelper.cs index 430e8138eb..54e6ce9d65 100644 --- a/src/Microsoft.AspNetCore.Blazor.Browser/Routing/UriHelper.cs +++ b/src/Microsoft.AspNetCore.Blazor.Browser/Routing/UriHelper.cs @@ -16,6 +16,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Routing public static class UriHelper { static readonly string _functionPrefix = typeof(UriHelper).FullName; + static string _currentAbsoluteUri; /// /// An event that fires when the navigation location has changed. @@ -48,8 +49,13 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Routing /// The browser's current absolute URI. public static string GetAbsoluteUri() { - return RegisteredFunction.InvokeUnmarshalled( + if (_currentAbsoluteUri == null) + { + _currentAbsoluteUri = RegisteredFunction.InvokeUnmarshalled( $"{_functionPrefix}.getLocationHref"); + } + + return _currentAbsoluteUri; } /// @@ -83,7 +89,10 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Routing } private static void NotifyLocationChanged(string newAbsoluteUri) - => OnLocationChanged?.Invoke(null, newAbsoluteUri); + { + _currentAbsoluteUri = newAbsoluteUri; + OnLocationChanged?.Invoke(null, newAbsoluteUri); + } /// /// Given the document's document.baseURI value, returns the URI prefix