Microsoft.aspnetcore.components.navigationexception: ‘exception_wasthrown’

The exception microsoft.aspnetcore.components.navigationexception: 'exception_wasthrown' is a navigation exception within the ASP.NET Core Components framework. This exception is typically thrown when there is an error during navigation within a web application.

To better understand this exception, let’s take a look at an example. Imagine we have a web application built using ASP.NET Core Components, and it has a navigation menu with multiple links. When a user clicks on one of the links, the application tries to navigate to a specific page or perform a specific action. However, an error occurs during this navigation process, resulting in the navigationexception being thrown.

Here’s an example of how this exception can be handled within the ASP.NET Core Components framework:

<Router AppAssembly="typeof(Program).Assembly">
    <Found>
        @if (foundContext.Exception is Microsoft.AspNetCore.Components.NavigationException)
        {
            <p>An error occurred during navigation: <code>@foundContext.Exception.Message</code></p>
        }
        else
        {
            <!-- Handle other exceptions or display the component content -->
            <MyComponent></MyComponent>
        }
    </Found>
    <!-- ... -->
</Router>

In this example, we have a Router component that acts as a top-level container for our application’s navigation. Inside the Found event handler, we can check if the foundContext.Exception is of type Microsoft.AspNetCore.Components.NavigationException. If it is, we display an error message indicating that an error occurred during navigation and provide the exception message.

If the exception is not a navigation exception, we can handle it differently or proceed normally with rendering our component content.

Read more interesting post

Leave a comment