navigationParams method

Future<NavigationParams> navigationParams(
  1. String path,
  2. NavigationParams params
)

Called by the router to transform the params before a route navigation.

The client should return a future that completes with the desired new NavigationParams for a specified route navigation.

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

class MyHook extends RouterHook {
  MyHook(this._injector);

  final Injector _injector;

  // Lazily inject `Router` to avoid cyclic dependency.
  Router _router;
  Router get router => _router ??= _injector.provideType(Router);

  @override
  Future<NavigationParams> navigationParams(
      String _, NavigationParams params) async {
    // Combine the query parameters with existing ones.
    return NavigationParams(
      queryParameters: {
        ...?router.current?.queryParameters,
        ...params.queryParameters,
      },
    );
  }
}

Implementation

Future<NavigationParams> navigationParams(
    String path, NavigationParams params) async {
  // Provided as a default if someone extends or mixes-in this interface.
  return params;
}