Add a Blazor built-in ErrorBoundary around @Body with a friendly FluentMessageBar + retry / home buttons. Also hook NavigationManager.LocationChanged so the boundary resets on any nav (otherwise the error state persists across NavigateTo and "Zur Startseite" still shows the failure banner). U-6 split into U-6a (this) and U-6b (per-handler try/catch to route expected exceptions to IMessageService — deferred). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
69 lines
No EOL
2.8 KiB
Text
69 lines
No EOL
2.8 KiB
Text
@inherits LayoutComponentBase
|
|
@inject NavigationManager Navigation
|
|
@implements IDisposable
|
|
|
|
<FluentLayout>
|
|
<FluentHeader Class="hidePrint">
|
|
<MyHeader/>
|
|
</FluentHeader>
|
|
<FluentStack Class="main" Orientation="Orientation.Horizontal" Width="100%">
|
|
<NavMenu />
|
|
<FluentBodyContent Class="body-content">
|
|
<FluentMessageBarProvider Section="MESSAGES_TOP" @rendermode="InteractiveServer" />
|
|
<div class="content">
|
|
<ErrorBoundary @ref="errorBoundary">
|
|
<ChildContent>
|
|
@Body
|
|
</ChildContent>
|
|
<ErrorContent>
|
|
<FluentStack Orientation="Orientation.Vertical" Style="padding: 2rem; max-width: 640px;">
|
|
<FluentMessageBar Intent="MessageIntent.Error"
|
|
Title="Ein Fehler ist aufgetreten"
|
|
AllowDismiss="false">
|
|
Diese Seite konnte nicht angezeigt werden. Details stehen im Server-Log.
|
|
</FluentMessageBar>
|
|
<FluentStack Orientation="Orientation.Horizontal">
|
|
<FluentButton Appearance="Appearance.Neutral" OnClick="Recover">Neu versuchen</FluentButton>
|
|
<FluentAnchor Href="/" Appearance="Appearance.Neutral">Zur Startseite</FluentAnchor>
|
|
</FluentStack>
|
|
</FluentStack>
|
|
</ErrorContent>
|
|
</ErrorBoundary>
|
|
</div>
|
|
</FluentBodyContent>
|
|
</FluentStack>
|
|
|
|
<FluentFooter Class="hidePrint" Style="padding: 25px 5px 5px 5px ">
|
|
AccountingNext App
|
|
<FluentSpacer/>
|
|
Copyright 2025 by Claudio Schaad
|
|
</FluentFooter>
|
|
</FluentLayout>
|
|
|
|
<FluentDialogProvider @rendermode="InteractiveServer"/>
|
|
<FluentToastProvider MaxToastCount="10" @rendermode="InteractiveServer" />
|
|
|
|
<div id="blazor-error-ui" data-nosnippet>
|
|
An unhandled error has occurred.
|
|
<a href="." class="reload">Reload</a>
|
|
<span class="dismiss">🗙</span>
|
|
</div>
|
|
|
|
@code {
|
|
private ErrorBoundary? errorBoundary;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// ErrorBoundary state persists across NavigationManager.NavigateTo, so the
|
|
// error page would linger even after the user clicked "Zur Startseite".
|
|
// Reset on any location change.
|
|
Navigation.LocationChanged += OnLocationChanged;
|
|
}
|
|
|
|
private void OnLocationChanged(object? sender, Microsoft.AspNetCore.Components.Routing.LocationChangedEventArgs e)
|
|
=> errorBoundary?.Recover();
|
|
|
|
private void Recover() => errorBoundary?.Recover();
|
|
|
|
public void Dispose() => Navigation.LocationChanged -= OnLocationChanged;
|
|
} |