Replaces a route that is not currently visible with a new route.
The new route and the route below the new route (if any) are notified (see Route.didReplace and Route.didChangeNext). The navigator observer is not notified. The old route is disposed (see Route.dispose).
This can be useful in combination with removeRouteBelow when building a non-linear user experience.
Source
void replace({ Route<dynamic> oldRoute, Route<dynamic> newRoute }) { assert(!_debugLocked); assert(oldRoute != null); assert(newRoute != null); if (oldRoute == newRoute) return; assert(() { _debugLocked = true; return true; }); assert(oldRoute._navigator == this); assert(newRoute._navigator == null); assert(oldRoute.overlayEntries.isNotEmpty); assert(newRoute.overlayEntries.isEmpty); assert(!overlay.debugIsVisible(oldRoute.overlayEntries.last)); setState(() { int index = _history.indexOf(oldRoute); assert(index >= 0); newRoute._navigator = this; newRoute.install(oldRoute.overlayEntries.last); _history[index] = newRoute; newRoute.didReplace(oldRoute); if (index + 1 < _history.length) newRoute.didChangeNext(_history[index + 1]); else newRoute.didChangeNext(null); if (index > 0) _history[index - 1].didChangeNext(newRoute); oldRoute.dispose(); oldRoute._navigator = null; }); assert(() { _debugLocked = false; return true; }); }