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
{
static readonly string _functionPrefix = typeof(UriHelper).FullName;
static string _currentAbsoluteUri;
/// <summary>
/// An event that fires when the navigation location has changed.
@ -48,10 +49,15 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Routing
/// <returns>The browser's current absolute URI.</returns>
public static string GetAbsoluteUri()
{
return RegisteredFunction.InvokeUnmarshalled<string>(
if (_currentAbsoluteUri == null)
{
_currentAbsoluteUri = RegisteredFunction.InvokeUnmarshalled<string>(
$"{_functionPrefix}.getLocationHref");
}
return _currentAbsoluteUri;
}
/// <summary>
/// Given a base URI prefix (e.g., one previously returned by <see cref="GetBaseUriPrefix"/>),
/// converts an absolute URI into one relative to the base URI prefix.
@ -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);
}
/// <summary>
/// Given the document's document.baseURI value, returns the URI prefix