canReuse method

Future<bool> canReuse(
  1. RouterState current,
  2. RouterState next
)

Called by the router before the route is deactivated, so that the component instance can notify the router if it should be cached for reuse.

If this interface is not implemented, the component is always destroyed and re-created; otherwise the client should return a future that completes with true in order to re-use this instance of the component, or completes with false in order to destroy and re-create a new instance.

You can use async in order to simplify when returning synchronously:

class MyComponent implements CanReuse {
  @override
  Future<bool> canReuse(RouterState current, RouterState next) async {
    // Always re-use this instance.
    return true;
  }
}

Or simply mixin or extend this class:

class MyComponent extends CanReuse {}

Implementation

Future<bool> canReuse(RouterState current, RouterState next) async {
  // Provided as a default if someone extends or mixes-in this interface.
  return true;
}