Table of Contents

Interface IConfirmExitService

Namespace
NuvTools.AspNetCore.Blazor.JSInterop
Assembly
NuvTools.AspNetCore.Blazor.dll

Asks the browser to confirm before the user closes or reloads the tab, or navigates away from the application.

public interface IConfirmExitService : IAsyncDisposable
Inherited Members

Examples

[Inject] IConfirmExitService ConfirmExit { get; set; } = default!;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (HasUnsavedChanges())
        await ConfirmExit.EnableAsync();
    else
        await ConfirmExit.DisableAsync();
}

public async ValueTask DisposeAsync() => await ConfirmExit.DisableAsync();

Remarks

The confirmation is raised by the browser through the beforeunload event, so the warning text is defined by the browser and cannot be customized. It does not cover in-app (SPA) navigation.

Properties

IsEnabled

Gets a value indicating whether the exit confirmation is currently active.

bool IsEnabled { get; }

Property Value

bool

Methods

DisableAsync(CancellationToken)

Deactivates the exit confirmation. Calling it while already inactive does nothing.

ValueTask DisableAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token to observe.

Returns

ValueTask

A ValueTask representing the asynchronous operation.

EnableAsync(CancellationToken)

Activates the exit confirmation. Calling it while already active does nothing.

ValueTask EnableAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A cancellation token to observe.

Returns

ValueTask

A ValueTask representing the asynchronous operation.