Method UseBlocker
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
UseBlocker(bool)
Blocks navigation departures while shouldBlock is true, as React Router's
useBlocker(boolean) does. The component re-renders whenever the returned Blocker's state
changes. Must be used inside Render() only.
public static RouteBlockerState UseBlocker(bool shouldBlock)
Parameters
shouldBlockboolWhether a departure is blocked.
Returns
- RouteBlockerState
The RouteBlockerState to render a confirmation from.
Exceptions
- InvalidOperationException
No
V.RouterProvideris mounted above the caller.
UseBlocker(Func<BlockerFunctionArgs, bool>)
Conditionally blocks navigation departures, handing the Blocker the predicate of every render so it answers with the state the latest render captured. The component re-renders whenever the returned Blocker's state changes. Must be used inside Render() only.
public static RouteBlockerState UseBlocker(Func<BlockerFunctionArgs, bool> shouldBlock)
Parameters
shouldBlockFunc<BlockerFunctionArgs, bool>Predicate; returning true blocks the departure.
Returns
- RouteBlockerState
The RouteBlockerState to render a confirmation from.
Remarks
The single-argument overload exists so that omitting deps is unambiguous — see UseCallback<T>(T) for the hazard it avoids.
Exceptions
- InvalidOperationException
No
V.RouterProvideris mounted above the caller.
UseBlocker(Func<BlockerFunctionArgs, bool>, params object?[]?)
Conditionally blocks navigation departures, handing the Blocker a render's predicate only when a dependency changes. The component re-renders whenever the returned Blocker's state changes. Must be used inside Render() only.
public static RouteBlockerState UseBlocker(Func<BlockerFunctionArgs, bool> shouldBlock, params object?[]? deps)
Parameters
shouldBlockFunc<BlockerFunctionArgs, bool>Predicate; returning true blocks the departure.
depsobject[]Dependency array. When null, every render's predicate is handed over.
Returns
- RouteBlockerState
The RouteBlockerState to render a confirmation from.
Exceptions
- InvalidOperationException
No
V.RouterProvideris mounted above the caller.