replaceNamed<T extends Object?> method

  1. @optionalTypeArgs
Future<T?> replaceNamed<T extends Object?>(
  1. String path, {
  2. bool includePrefixMatches = false,
  3. OnNavigationFailure? onFailure,
})

Removes last entry in stack and pushes given path if last entry.path == path page will just be updated

if includePrefixMatches is true prefixed-matches will be added to to target destination see RouteMatcher.matchUri

if onFailure callback is provided, navigation errors will be passed to it otherwise they'll be thrown

Implementation

@optionalTypeArgs
Future<T?> replaceNamed<T extends Object?>(
  String path, {
  bool includePrefixMatches = false,
  OnNavigationFailure? onFailure,
}) {
  final scope = _findPathScopeOrReportFailure<StackRouter>(
    path,
    includePrefixMatches: includePrefixMatches,
    onFailure: onFailure,
  );
  if (scope != null) {
    scope.router._removeLast(notify: false);
    markUrlStateForReplace();
    return scope.router._pushAllGuarded(
      scope.matches,
      onFailure: onFailure,
    );
  }
  return SynchronousFuture(null);
}