Skip to content

[go_router] Add BlockedInitialNavigationException for blocked initial deep links#12213

Open
davidmigloz wants to merge 2 commits into
flutter:mainfrom
davidmigloz:upstream-blocked-initial-navigation-exception
Open

[go_router] Add BlockedInitialNavigationException for blocked initial deep links#12213
davidmigloz wants to merge 2 commits into
flutter:mainfrom
davidmigloz:upstream-blocked-initial-navigation-exception

Conversation

@davidmigloz

Copy link
Copy Markdown
Contributor

When onEnter returns Block.stop() on the very first navigation attempt (e.g. a deep link on web, before any route has been committed), the parser's onCanNotEnter path has no prior configuration to restore and reports a generic GoException. Apps handling this in onException can't tell "initial deep link blocked" apart from other routing errors (unmatched routes, redirect loops) without string matching on the exception message.

This adds BlockedInitialNavigationException extends GoException, raised specifically in that no-prior-route path. It only refines the exception type — no change to when or whether an exception is thrown, and existing is GoException checks keep working. Apps can now write if (state.error is BlockedInitialNavigationException) in onException and, for example, redirect to a loading screen with the deep link preserved instead of treating it as a 404.

Test: widget test in on_enter_test.dart — initial navigation blocked by Block.stop() with an onException handler; asserts the captured state.error is a BlockedInitialNavigationException (and still a GoException).

Fixes flutter/flutter#189581

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

… deep links

When Block.stop() is returned from onEnter with no prior route
configuration (e.g. an initial deep link), the parser now raises a
typed BlockedInitialNavigationException instead of a generic
GoException, so apps can distinguish this case in onException without
string matching.
@github-actions github-actions Bot added p: go_router triage-framework Should be looked at in framework triage labels Jul 16, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces BlockedInitialNavigationException, a subtype of GoException, which is raised when initial navigation is blocked by onEnter without a prior route to restore. The parser is updated to throw this new exception, and a test case is added to verify this behavior. Feedback suggests removing the square brackets around Block in the documentation comments of BlockedInitialNavigationException to avoid unresolved doc reference warnings, since Block is not in scope in errors.dart.

Comment thread packages/go_router/lib/src/misc/errors.dart Outdated
@davidmigloz

davidmigloz commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Heads-up: the onException recovery pattern this exception enables (redirecting away from a blocked initial deep link) only works end-to-end once #12216 lands, that one fixes an assertion crash when onException fires on the initial navigation (flutter/flutter#189582). The two are mergeable independently; landing #12216 first just means the typed exception ships with a working recovery path from day one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: go_router triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go_router] Cannot distinguish a blocked initial deep link from other routing errors in onException

1 participant