Skip to content

Add NotFound method in NavigationManager for interactive and static rendering #60752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feedback.
  • Loading branch information
ilonatommy committed Mar 10, 2025
commit bfa81451daf6e224f3f861e9f8760a8e01804f57
20 changes: 4 additions & 16 deletions src/Components/Components/src/NavigationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ public virtual void Refresh(bool forceReload = false)
/// <summary>
/// Handles setting the NotFound state.
/// </summary>
protected virtual void NotFoundCore() => throw new NotImplementedException();
protected virtual void NotFoundCore()
{
_notFound?.Invoke(this, new EventArgs());
}

/// <summary>
/// Called to initialize BaseURI and current URI before these values are used for the first time.
Expand Down Expand Up @@ -337,21 +340,6 @@ protected void NotifyLocationChanged(bool isInterceptedLink)
}
}

/// <summary>
/// Triggers the <see cref="NotFound"/> event with the current URI value.
/// </summary>
protected void NotifyNotFound()
{
try
{
_notFound?.Invoke(this, new EventArgs());
}
catch (Exception ex)
{
throw new NotFoundRenderingException("An exception occurred while dispatching a NotFound event.", ex);
}
}

/// <summary>
/// Notifies the registered handlers of the current location change.
/// </summary>
Expand Down
20 changes: 0 additions & 20 deletions src/Components/Components/src/NotFoundRenderingException.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/Components/Components/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
Microsoft.AspNetCore.Components.IEndpointHtmlRenderer
Microsoft.AspNetCore.Components.IEndpointHtmlRenderer.SetNotFoundResponse() -> void
Microsoft.AspNetCore.Components.NavigationManager.NotFoundEvent -> System.EventHandler<System.EventArgs!>!
Microsoft.AspNetCore.Components.NavigationManager.NotifyNotFound() -> void
Microsoft.AspNetCore.Components.NotFoundRenderingException
Microsoft.AspNetCore.Components.NotFoundRenderingException.NotFoundRenderingException(string! message, System.Exception! innerException) -> void
Microsoft.AspNetCore.Components.Routing.IHostEnvironmentNavigationManager.Initialize(string! baseUri, string! uri, Microsoft.AspNetCore.Components.IEndpointHtmlRenderer! renderer) -> void
virtual Microsoft.AspNetCore.Components.NavigationManager.NotFound() -> void
virtual Microsoft.AspNetCore.Components.NavigationManager.NotFoundCore() -> void
19 changes: 0 additions & 19 deletions src/Components/Server/src/Circuits/RemoteNavigationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,6 @@ async Task RefreshAsync()
}
}

/// <inheritdoc />
protected override void NotFoundCore()
{
Log.RequestingNotFound(_logger);

try
{
NotifyNotFound();
}
catch (Exception ex)
{
Log.NotFoundRenderFailed(_logger, ex);
UnhandledException?.Invoke(this, ex);
}
}

protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context)
{
Log.NavigationFailed(_logger, context.TargetLocation, ex);
Expand Down Expand Up @@ -233,8 +217,5 @@ public static void RequestingNavigation(ILogger logger, string uri, NavigationOp

[LoggerMessage(7, LogLevel.Debug, "Navigation stopped because the session ended when navigating to {Uri}", EventName = "NavigationStoppedSessionEnded")]
public static partial void NavigationStoppedSessionEnded(ILogger logger, string uri);

[LoggerMessage(8, LogLevel.Error, "Failed to render NotFound", EventName = "NotFoundRenderFailed")]
public static partial void NotFoundRenderFailed(ILogger logger, Exception exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ public override void Refresh(bool forceReload = false)
DefaultWebAssemblyJSRuntime.Instance.InvokeVoid(Interop.Refresh, forceReload);
}

/// <inheritdoc />
protected override void NotFoundCore()
{
try
{
NotifyNotFound();
}
catch (Exception ex)
{
Log.NotFoundRenderFailed(_logger, ex);
}
}

protected override void HandleLocationChangingHandlerException(Exception ex, LocationChangingContext context)
{
Log.NavigationFailed(_logger, context.TargetLocation, ex);
Expand All @@ -113,8 +100,5 @@ private static partial class Log

[LoggerMessage(2, LogLevel.Error, "Navigation failed when changing the location to {Uri}", EventName = "NavigationFailed")]
public static partial void NavigationFailed(ILogger logger, string uri, Exception exception);

[LoggerMessage(3, LogLevel.Error, "Failed to render NotFound", EventName = "NotFoundRenderFailed")]
public static partial void NotFoundRenderFailed(ILogger logger, Exception exception);
}
}
Loading