I have most of the error handling working, except for one thing.
In my layout.razor
page, I have:
<ErrorBoundary @ref="errorBoundary">
<ChildContent>
@Body
</ChildContent>
<ErrorContent>
<Error ErrorDetail="@context"></Error>
</ErrorContent>
</ErrorBoundary>
Now in any of my pages that throw a general error, I receive an error page as expected in the body of my app. This means that the user is still able to select other parts of the app once they have seen the error. All good.
The issue I now have is that in my routes.razor
I have:
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<FocusOnNavigate RouteData="routeData" Selector="h1" />
</Found>
<NotFound>
<Error ErrorDetail='new Exception("Route Not Found")' />
</NotFound>
</Router>
Now if the route isn't found it correctly goes to the <NotFound>
element and shows the correct error. Trouble is it is on whole page and isn't within the body. I understand why that is, but is there a way that under this circumstance I can get the error showing in the body of the app?
You could wrap the component in LayoutView
<NotFound>
<LayoutView Layout="@typeof(Layout.MainLayout)">
<Error ErrorDetail='new Exception("Route Not Found")' />
</LayoutView>
</NotFound>