[go_router] Add BlockedInitialNavigationException for blocked initial deep links#12213
[go_router] Add BlockedInitialNavigationException for blocked initial deep links#12213davidmigloz wants to merge 2 commits into
Conversation
… 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.
There was a problem hiding this comment.
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.
|
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. |
When
onEnterreturnsBlock.stop()on the very first navigation attempt (e.g. a deep link on web, before any route has been committed), the parser'sonCanNotEnterpath has no prior configuration to restore and reports a genericGoException. Apps handling this inonExceptioncan'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 existingis GoExceptionchecks keep working. Apps can now writeif (state.error is BlockedInitialNavigationException)inonExceptionand, 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 byBlock.stop()with anonExceptionhandler; asserts the capturedstate.erroris aBlockedInitialNavigationException(and still aGoException).Fixes flutter/flutter#189581
Pre-Review Checklist
[shared_preferences]///).Footnotes
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