push<T extends Object?> method

  1. @optionalTypeArgs
NavigationResult<T> push<T extends Object?>(
  1. String path, {
  2. Map<String, String>? queryParameters,
})

Navigates to path.

If this path starts with a forward slash, it's treated as an absolute path. Otherwise it's handled as a path relative to the current route.

For example, if the current route is '/products':

  • Calling push('1') navigates to '/products/1'.

  • Calling push('/home') navigates to '/home'.

A queryParameters map can be added to pass string parameters to the new route:

push('/search', queryParameters: {'query': 'hello'})

These can then be access from RouteData, using RouteData.of(context).queryParameters, or from within a route map:

'/product': (route) => MaterialPage(child: SearchPage(route.queryParameters['id']))

Implementation

@optionalTypeArgs
NavigationResult<T> push<T extends Object?>(
  String path, {
  Map<String, String>? queryParameters,
}) {
  final routeData = RouteData.maybeOf(_context);
  if (routeData != null) {
    // Use context route data for relative path
    return _state.delegate._pushUri<T>(
      PathParser.getAbsolutePath(
        basePath: routeData.fullPath,
        path: path,
        queryParameters: queryParameters,
      ),
      queryParameters: queryParameters,
    );
  }

  return _state.delegate.push<T>(path, queryParameters: queryParameters);
}