canNavigate method

Future<bool> canNavigate()

Called by the router to indicate if navigation is allowed.

The client should return a future that completes with the whether the navigation can happen. If the component extends the CanNavigate lifecycle, that will override this behavior.

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

class MyHook extends RouterHook {
  final Window _window;

  @override
  Future<bool> canNavigate() async {
    // Always ask if the user wants to navigate away from the page.
    return _window.confirm('Discard changes?');
  }
}

Implementation

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