GoRouter.dev

Historical source · 2021–2022

日本語アーカイブ · ルートのデバッグ

原文・コード例・画像を保存した2021–2022年のドキュメント。

Edition published 21 Oct 2026Original APIs
On this page
これは2021–2022年の原文アーカイブです。旧APIの例が含まれます。2026年版の英語ガイドも参照してください。

ルートのデバッグ

go_router では GoRoute を通じてパスを設定しますが、そのパスはロケーション名の一部でしかない場合もあります。 そのため、アプリ内にどのようなルートが設定されているのか全体像を把握しづらいことがありますが、 デバッグツールを使えばルートの通しパス一覧を簡単に確認することができます。

text / example
GoRouter: known full paths for routes:
GoRouter:   => /
GoRouter:   =>   /family/:fid
GoRouter:   =>     /family/:fid/person/:pid
GoRouter: known full paths for route names:
GoRouter:   home => /
GoRouter:   family => /family/:fid
GoRouter:   person => /family/:fid/person/:pid

また、go_router はナビゲートする方法が多様で(context.go()、context.goNamed()、context.push()、context.pushNamed()、Link ウィジェット、その他) リダイレクトの方法も複数あるため、これらが実際に裏側で行っている動作を確認したい場合があります。 これについてもデバッグツールで確認することができます。

text / example
GoRouter: setting initial location /
GoRouter: location changed to /
GoRouter: getting location for name: "person", params: {fid: f2, pid: p1}
GoRouter: going to /family/f2/person/p1
GoRouter: location changed to /family/f2/person/p1

さらに、アプリ内画面を生成するビルダーとして pageBuilder の代わりに builder を使用した場合は、 go_router が認識しているアプリの種類を確認することができます。ページ間のトランジション効果はこのアプリの種類により異なります。

text / example
GoRouter: MaterialApp found

最後に、ルーティングに関する例外が発生した場合はコールスタックとともにデバッグ出力で確認することができます。

text / example
GoRouter: Exception: no routes for location: /foobarquux
...call stack elided...

このような出力を有効にするには GoRouter 作成時に debugLogDiagnostics を設定します。

dart / example
final _router = GoRouter(
  routes: ...,

  // ルート診断情報の出力を有効にする
  debugLogDiagnostics: true,
);

このパラメータは false(出力なし)がデフォルトです。

Sources & version context

GoRouter.dev documentation edition. The preserved text describes the original package APIs. Follow the current guide before using it in a new project.

Find your next route