Q:

How do you handle 404 pages in Blazor?

0

This code will help you to understand how to handle 404 pages in Blazor.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The NotFound template section in the App.razor can be used for handling 404 pages. The router shows this content if it hits a route that is not available, which is a 404 page.

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Handled 404 page</p>
        </LayoutView>
    </NotFound>
</Router>

Create a component Page/Error.razor to display the 404 content.

I would suggest you check the below link for better understanding:

https://docs.microsoft.com/en-us/aspnet/core/blazor/routing?view=aspnetcore-3.0#route-templates

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now