Skip to content
This repository has been archived by the owner on Feb 25, 2021. It is now read-only.

Overload UriHelper to forceLoad the page even if it's not a Blazor defined Route. #1154

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ function enableNavigationInterception(assemblyName: string, functionName: string
window.addEventListener('popstate', handleInternalNavigation);
}

export function navigateTo(uri: string) {
export function navigateTo(uri: string, forceLoad: boolean) {
const absoluteUri = toAbsoluteUri(uri);
if (isWithinBaseUriSpace(absoluteUri)) {

if (forceLoad) {
location.href = uri;
} else if (isWithinBaseUriSpace(absoluteUri)) {
performInternalNavigation(absoluteUri);
} else {
location.href = uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ protected override void InitializeState()
}

/// <inheritdoc />
protected override void NavigateToCore(string uri)
protected override void NavigateToCore(string uri, bool forceLoad)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}

((IJSInProcessRuntime)JSRuntime.Current).Invoke<object>(Interop.NavigateTo, uri);
((IJSInProcessRuntime)JSRuntime.Current).Invoke<object>(Interop.NavigateTo, uri, forceLoad);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ public static void NotifyLocationChanged(string uriAbsolute)
uriHelper.TriggerOnLocationChanged();
}

/// <summary>
/// Navigates to the specified URI.
/// </summary>
/// <param name="uri">The destination URI. This can be absolute, or relative to the base URI
/// (as returned by <see cref="IUriHelper.GetBaseUri"/>).</param>
protected override void NavigateToCore(string uri)
/// <inheritdoc />
protected override void NavigateToCore(string uri, bool forceLoad)
{
_jsRuntime.InvokeAsync<object>(Interop.NavigateTo, uri);
_jsRuntime.InvokeAsync<object>(Interop.NavigateTo, uri, forceLoad);
}
}
}
3 changes: 2 additions & 1 deletion src/Microsoft.AspNetCore.Blazor/Services/IUriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public interface IUriHelper
/// </summary>
/// <param name="uri">The destination URI. This can be absolute, or relative to the base URI
/// (as returned by <see cref="GetBaseUri"/>).</param>
void NavigateTo(string uri);
/// <param name="forceLoad">Indicator to force load the URI, even if it's not a blazor route.</param>
void NavigateTo(string uri, bool forceLoad = false);
}
}
8 changes: 5 additions & 3 deletions src/Microsoft.AspNetCore.Blazor/Services/UriHelperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ public abstract class UriHelperBase : IUriHelper
/// </summary>
/// <param name="uri">The destination URI. This can be absolute, or relative to the base URI
/// (as returned by <see cref="GetBaseUri"/>).</param>
public void NavigateTo(string uri)
/// <param name="forceLoad">Indicator to force load the URI, even if it's not a blazor route.</param>
public void NavigateTo(string uri, bool forceLoad = false)
{
EnsureInitialized();
NavigateToCore(uri);
NavigateToCore(uri, forceLoad);
}

/// <summary>
/// Navigates to the specified URI.
/// </summary>
/// <param name="uri">The destination URI. This can be absolute, or relative to the base URI
/// (as returned by <see cref="GetBaseUri"/>).</param>
protected abstract void NavigateToCore(string uri);
/// <param name="forceLoad">Indicator to force load the URI, even if it's not a blazor route.</param>
protected abstract void NavigateToCore(string uri, bool forceLoad);

/// <summary>
/// Called to initialize BaseURI and current URI before those values the first time.
Expand Down