of static method

AppRouter of(
  1. BuildContext context, {
  2. bool root = false,
})

Sets the URL strategy of your web app to using paths instead of a leading hash (#).

You can safely call this on all platforms, i.e. also when running on mobile or desktop. In that case, it will simply be a noop.

Web アプリの URL 戦略を、先頭のハッシュ (#) の代わりにパスを使用するように設定します。

これは、すべてのプラットフォームで安全に呼び出すことができます。つまり、モバイルまたはデスクトップで実行している場合でも同様です。その場合、それは単にヌープになります。 Get AppRouter placed on the widget tree.

Setting root to true will get AppRouter at the top level.

ウィジェットツリー上に配置されているAppRouterを取得します。

roottrueにすると最上位にあるAppRouterを取得します。

Implementation

// TODO: 非アクティブにするが、一応残しておく
// static void setPathUrlStrategy() => url_strategy.setPathUrlStrategy();

/// Get [AppRouter] placed on the widget tree.
///
/// Setting [root] to `true` will get [AppRouter] at the top level.
///
/// ウィジェットツリー上に配置されている[AppRouter]を取得します。
///
/// [root]を`true`にすると最上位にある[AppRouter]を取得します。
static AppRouter of(BuildContext context, {bool root = false}) {
  final navigator = Navigator.of(context, rootNavigator: root).context;
  final scope = navigator
      .getElementForInheritedWidgetOfExactType<AppRouteScope>()
      ?.widget as AppRouteScope?;
  assert(scope != null, "AppRouter is not found.");
  return scope!.router;
}