In UriHelper, cache current absolute URL

This commit is contained in:
Steve Sanderson 2018-02-21 09:41:57 +00:00
parent b764029ce0
commit 6f25663a32
1 changed files with 11 additions and 2 deletions

View File

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