From 6f25663a32a2d3dc38905230094a689a501a8e6d Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Wed, 21 Feb 2018 09:41:57 +0000 Subject: [PATCH] In UriHelper, cache current absolute URL --- .../Routing/UriHelper.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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