diff --git a/src/Components/Components/src/NavigationManager.cs b/src/Components/Components/src/NavigationManager.cs
index e5752e669a38..be2c302b67e5 100644
--- a/src/Components/Components/src/NavigationManager.cs
+++ b/src/Components/Components/src/NavigationManager.cs
@@ -90,10 +90,11 @@ protected set
/// The destination URI. This can be absolute, or relative to the base URI
/// (as returned by ).
/// If true, bypasses client-side routing and forces the browser to load the new page from the server, whether or not the URI would normally be handled by the client-side router.
- public void NavigateTo(string uri, bool forceLoad = false)
+ /// If true, navigation will not trigger the event.
+ public void NavigateTo(string uri, bool forceLoad = false, bool suppressLocationChanged = false)
{
AssertInitialized();
- NavigateToCore(uri, forceLoad);
+ NavigateToCore(uri, forceLoad, suppressLocationChanged);
}
///
@@ -102,7 +103,8 @@ public void NavigateTo(string uri, bool forceLoad = false)
/// The destination URI. This can be absolute, or relative to the base URI
/// (as returned by ).
/// If true, bypasses client-side routing and forces the browser to load the new page from the server, whether or not the URI would normally be handled by the client-side router.
- protected abstract void NavigateToCore(string uri, bool forceLoad);
+ /// If true, navigation will not trigger the event.
+ protected abstract void NavigateToCore(string uri, bool forceLoad, bool suppressLocationChanged);
///
/// Called to initialize BaseURI and current URI before these values are used for the first time.
diff --git a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs
index b57130c29a30..af1198de64f6 100644
--- a/src/Components/Server/src/Circuits/RemoteNavigationManager.cs
+++ b/src/Components/Server/src/Circuits/RemoteNavigationManager.cs
@@ -56,16 +56,20 @@ public void AttachJsRuntime(IJSRuntime jsRuntime)
_jsRuntime = jsRuntime;
}
- public void NotifyLocationChanged(string uri, bool intercepted)
+ public void NotifyLocationChanged(string uri, bool intercepted, bool suppressLocationChanged = false)
{
Log.ReceivedLocationChangedNotification(_logger, uri, intercepted);
Uri = uri;
- NotifyLocationChanged(intercepted);
+
+ if (!suppressLocationChanged)
+ {
+ NotifyLocationChanged(intercepted);
+ }
}
///
- protected override void NavigateToCore(string uri, bool forceLoad)
+ protected override void NavigateToCore(string uri, bool forceLoad, bool suppressLocationChanged)
{
Log.RequestingNavigation(_logger, uri, forceLoad);
@@ -75,7 +79,7 @@ protected override void NavigateToCore(string uri, bool forceLoad)
throw new NavigationException(absoluteUriString);
}
- _jsRuntime.InvokeAsync
[JSInvokable(nameof(NotifyLocationChanged))]
- public static void NotifyLocationChanged(string uri, bool isInterceptedLink)
+ public static void NotifyLocationChanged(string uri, bool isInterceptedLink, bool suppressLocationChanged)
{
- WebAssemblyNavigationManager.Instance.SetLocation(uri, isInterceptedLink);
+ WebAssemblyNavigationManager.Instance.SetLocation(uri, isInterceptedLink, suppressLocationChanged);
}
///
diff --git a/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyNavigationManager.cs b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyNavigationManager.cs
index 3fda8eaee861..4797116934ab 100644
--- a/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyNavigationManager.cs
+++ b/src/Components/WebAssembly/WebAssembly/src/Services/WebAssemblyNavigationManager.cs
@@ -22,21 +22,25 @@ public WebAssemblyNavigationManager(string baseUri, string uri)
Initialize(baseUri, uri);
}
- public void SetLocation(string uri, bool isInterceptedLink)
+ public void SetLocation(string uri, bool isInterceptedLink, bool suppressLocationChanged)
{
Uri = uri;
- NotifyLocationChanged(isInterceptedLink);
+
+ if (!suppressLocationChanged)
+ {
+ NotifyLocationChanged(isInterceptedLink);
+ }
}
///
- protected override void NavigateToCore(string uri, bool forceLoad)
+ protected override void NavigateToCore(string uri, bool forceLoad, bool suppressLocationChanged)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
- DefaultWebAssemblyJSRuntime.Instance.Invoke(Interop.NavigateTo, uri, forceLoad);
+ DefaultWebAssemblyJSRuntime.Instance.Invoke(Interop.NavigateTo, uri, forceLoad, suppressLocationChanged);
}
}
}
diff --git a/src/Mvc/Mvc.ViewFeatures/src/Infrastructure/HttpNavigationManager.cs b/src/Mvc/Mvc.ViewFeatures/src/Infrastructure/HttpNavigationManager.cs
index 56d881387782..a2fad238934d 100644
--- a/src/Mvc/Mvc.ViewFeatures/src/Infrastructure/HttpNavigationManager.cs
+++ b/src/Mvc/Mvc.ViewFeatures/src/Infrastructure/HttpNavigationManager.cs
@@ -10,7 +10,7 @@ internal class HttpNavigationManager : NavigationManager, IHostEnvironmentNaviga
{
void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri) => Initialize(baseUri, uri);
- protected override void NavigateToCore(string uri, bool forceLoad)
+ protected override void NavigateToCore(string uri, bool forceLoad, bool suppressLocationChanged)
{
throw new NavigationException(uri);
}
diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components.netstandard2.0.cs
index 6a5ff2c2e3a3..a6d07325fc2c 100644
--- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components.netstandard2.0.cs
+++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.ComponentShim/Microsoft.AspNetCore.Components.netstandard2.0.cs
@@ -279,8 +279,8 @@ protected NavigationManager() { }
public event System.EventHandler LocationChanged { add { } remove { } }
protected virtual void EnsureInitialized() { }
protected void Initialize(string baseUri, string uri) { }
- public void NavigateTo(string uri, bool forceLoad = false) { }
- protected abstract void NavigateToCore(string uri, bool forceLoad);
+ public void NavigateTo(string uri, bool forceLoad = false, bool suppressLocationChanged = false) { }
+ protected abstract void NavigateToCore(string uri, bool forceLoad, bool suppressLocationChanged);
protected void NotifyLocationChanged(bool isInterceptedLink) { }
public System.Uri ToAbsoluteUri(string relativeUri) { throw null; }
public string ToBaseRelativePath(string uri) { throw null; }