replaceNamed<E> method

Future<E?> replaceNamed<E>(
  1. String path, [
  2. TransitionQuery? transitionQuery
])

Finds a RouteQuery that matches the path in the list of pages passed to AppRouter.pages and replaces the currently displayed page with that page.

The method of page transition can be specified with transitionQuery.

You can wait until the page is destroyed by the pop method with the return value Future.

In doing so, it can also receive the object passed by pop.

AppRouter.pagesに渡したページリストからpathに当てはまるRouteQueryを探し出しそちらのページに現在表示されているページを置き換えます。

ページ遷移の方法をtransitionQueryで指定可能です。

戻り値のFuturepopメソッドでページが破棄されるまで待つことができます。

また、その際popで渡されたオブジェクトを受け取ることができます。

Implementation

Future<E?> replaceNamed<E>(
  String path, [
  TransitionQuery? transitionQuery,
]) async {
  for (final page in pages) {
    final resolved = page.resolve(path);
    if (resolved != null) {
      return replace<E>(
        resolved,
        transitionQuery,
      );
    }
  }
  throw Exception("No $path found.");
}