Goal: Use app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");so that whenever the user tries to navigate to a page which does not exist, this will be caught by the middleware and load a razor component such as:
@page "/StatusCode/404"@inject NavigationManager Navigation<h3>Page Not Found (404)</h3><p>Sorry, we couldn’t find what you’re looking for.</p><p><a href="/">Back to Home</a></p>But this is not happening. Instead, when I add this middleware, the <NotFound> component in Routes.razor is triggered:
<CascadingAuthenticationState><Router AppAssembly="typeof(Program).Assembly"><Found Context="routeData"><AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" /><SessionCheck/></Found><NotFound><LayoutView Layout="@typeof(Layout.MainLayout)"><p>Sorry, there's nothing at this address. bogaboga</p></LayoutView></NotFound></Router></CascadingAuthenticationState>This is unexpected behaviour: Previously, the 'NotFound' component has never before been triggered, and that it is triggered is not supposed to happen:
Blazor Web Apps don't use the NotFound parameter (... markup), but the parameter is supported† for backward compatibility to avoid a breaking change in the framework
I am, however, able to use app.UseStatusCodePagesWithRedirects("/StatusCode/{0}");, but this triggers a redirect, which is not what I want: I want the user to stay on whatever url they typed in, but with the contents of the razor components @page "/StatusCode/404" for instance.
I have read what microsoft writes about UseStatusCodePagesWithReExecute and this stackoverflow post, but I can't figure out what's wrong here. I have also tried my code both on localhost and in a docker container, with the same behaviour for both cases.