dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.37k stars 9.99k forks source link

Blazor Net 8 interactive auto <NotFound> not triggerd #52660

Closed mihaimyh closed 10 months ago

mihaimyh commented 10 months ago

Is there an existing issue for this?

Describe the bug

Using the default template of Blazor with interactive mode set to auto (server and webassembly) we are getting the Routes.razor in the server project.

I've added also the component to display some pretty 404 page, but it seems it is not working, the browser's default 404 page is getting displayed:

<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(Client._Imports).Assembly }">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(Layout.MainLayout)">
            <h1>Not Found</h1>
        </LayoutView>
    </NotFound>
</Router>

image

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

MariovanZeist commented 10 months ago

Hi @mihaimyh This is a duplicate of https://github.com/dotnet/aspnetcore/issues/52251 potentially more info also here https://github.com/dotnet/aspnetcore/issues/48983

javiercn commented 10 months ago

@MariovanZeist is correct.

mandeep-sps commented 10 months ago

@javiercn @MariovanZeist Not Found is not working in Blazor Dotnet 8. I have added these line of Code:-

<NotFound>
    <LayoutView Layout="@typeof(Layout.MainLayout)">
        <h1>Not Found</h1>
    </LayoutView>
</NotFound>

Please help me on this part.

mandeep-sps commented 10 months ago

Hi team I got the Solution:-

app.UseStatusCodePagesWithRedirects("/404");

app.Run();
Add a _404.razor page to your Pages folder.

@page "/404"
<h3>Show me 404</h3>
@code {

}

Dotnet 8 Web app Template