replaceRouteBelow<T extends Object?> static method

  1. @optionalTypeArgs
void replaceRouteBelow<T extends Object?>(
  1. BuildContext context,
  2. {required Route anchorRoute,
  3. required Route<T> newRoute}

Replaces a route on the navigator that most tightly encloses the given context with a new route. The route to be replaced is the one below the given anchorRoute.

The old route must not be current visible, as this method skips the animations and therefore the removal would be jarring if it was visible. To replace the top-most route, consider pushReplacement instead, which does animate the new route, and delays removing the old route until the new route has finished animating.

The removed route is removed without being completed, so this method does not take a return value argument.

The new route, the route below the new route (if any), and the route above the new route, are all notified (see Route.didReplace, Route.didChangeNext, and Route.didChangePrevious). If the Navigator has any Navigator.observers, they will be notified as well (see NavigatorObserver.didReplace). The removed route is disposed without being notified. The future that had been returned from pushing that routes will not complete.

The T type argument is the type of the return value of the new route.

See also:

  • replace, which is the same but identifies the route to be removed directly.
  • restorableReplaceRouteBelow, which adds a replacement route that can be restored during state restoration.


static void replaceRouteBelow<T extends Object?>(BuildContext context, { required Route<dynamic> anchorRoute, required Route<T> newRoute }) {
  return Navigator.of(context).replaceRouteBelow<T>(anchorRoute: anchorRoute, newRoute: newRoute);