Method UseBlocker
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
UseBlocker(Func<NavigationAttempt, bool>)
Conditionally blocks navigation departures (synchronous variant), re-registering the predicate on every render so it answers with the state the latest render captured. Must be used inside Render() only.
public static RouteBlockerState UseBlocker(Func<NavigationAttempt, bool> shouldBlock)
Parameters
shouldBlockFunc<NavigationAttempt, bool>Predicate delegate; returning true blocks the departure.
Returns
- RouteBlockerState
The shared RouteBlockerState handle for inspecting / resolving the pending departure.
Remarks
The single-argument overload exists so that omitting deps is unambiguous — see UseCallback<T>(T) for the hazard it avoids.
UseBlocker(Func<NavigationAttempt, bool>, params object?[]?)
Conditionally blocks navigation departures (synchronous variant), re-registering the predicate only when a dependency changes. Must be used inside Render() only.
public static RouteBlockerState UseBlocker(Func<NavigationAttempt, bool> shouldBlock, params object?[]? deps)
Parameters
shouldBlockFunc<NavigationAttempt, bool>Predicate delegate; returning true blocks the departure.
depsobject[]Dependency array. When null, re-registers on every render.
Returns
- RouteBlockerState
The shared RouteBlockerState handle for inspecting / resolving the pending departure.
UseBlocker(Func<NavigationAttempt, CancellationToken, VelvetTask<bool>>)
Conditionally blocks navigation departures (asynchronous variant), re-registering the predicate on every render so it answers with the state the latest render captured. Use when integrating with asynchronous UI such as confirmation dialogs.
public static RouteBlockerState UseBlocker(Func<NavigationAttempt, CancellationToken, VelvetTask<bool>> shouldBlock)
Parameters
shouldBlockFunc<NavigationAttempt, CancellationToken, VelvetTask<bool>>Async predicate; returning true blocks the departure. The CancellationToken is cancelled on unmount.
Returns
- RouteBlockerState
The shared RouteBlockerState handle for inspecting / resolving the pending departure.
Remarks
The single-argument overload exists so that omitting deps is unambiguous — see UseCallback<T>(T) for the hazard it avoids.
UseBlocker(Func<NavigationAttempt, CancellationToken, VelvetTask<bool>>, params object?[]?)
Conditionally blocks navigation departures (asynchronous variant), re-registering the predicate only when a dependency changes. Use when integrating with asynchronous UI such as confirmation dialogs.
public static RouteBlockerState UseBlocker(Func<NavigationAttempt, CancellationToken, VelvetTask<bool>> shouldBlock, params object?[]? deps)
Parameters
shouldBlockFunc<NavigationAttempt, CancellationToken, VelvetTask<bool>>Async predicate; returning true blocks the departure. The CancellationToken is cancelled on unmount.
depsobject[]Dependency array. When null, re-registers on every render.
Returns
- RouteBlockerState
The shared RouteBlockerState handle for inspecting / resolving the pending departure.