Defines route lifecycle method routerCanDeactivate, which is called by the router to determine if a component can be removed as part of a navigation.

The routerCanDeactivate hook is called with two ComponentInstructions as parameters, the first representing the current route being navigated to, and the second parameter representing the previous route.

If routerCanDeactivate returns or resolves to false, the navigation is cancelled. If it returns or resolves to true, then the navigation continues, and the component will be deactivated (the OnDeactivate hook will be run) and removed.

If routerCanDeactivate throws or rejects, the navigation is also cancelled.

Example

@override
FutureOr<bool> routerCanDeactivate(next, prev) =>
    crisis == null || crisis.name == name
        ? true as FutureOr<bool>
        : _dialogService.confirm('Discard changes?');

See the router documentation for details.

Constructors

CanDeactivate()

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

routerCanDeactivate(ComponentInstruction nextInstruction, ComponentInstruction prevInstruction) → dynamic
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(other) → bool
The equality operator. [...]
inherited