-
Notifications
You must be signed in to change notification settings - Fork 26.6k
fix(router): navigate to root if initial navigation fails #46648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Edit: Just one failure that is a screenshot test showing the new correct behavior. The old screenshot showed just a blank screen (plus the app header) with an error popup. |
43522ab
to
94ffa50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atscott looks great, just a couple comments on potential DX improvement and a corner case when navigation to /
also fails.
When a navigation in the router fails, we reset the internal state and browser URL to the last successful navigation. For the initial navigation, this does not exist, so `''`/`'/'` is used. Prior to this commit, the state reset was not also accompanied by a navigation to the root of the application. This results in a "blank" screen (or rather, it only shows content that is outside the `router-outlet` such as the static app header). With this commit, the router initializer, which includes an `initialNavigation` call, now tracks whether the initial navigation succeeded (including redirects). If the navigation did not succeed, a navigation to the root of the application is triggered (`'/'`). Again, this is in addition to what the router already does for this failed navigation: setting its internal state and browser URL to the root. Fixes angular#16211
When a navigation in the router fails, we reset the internal state and
browser URL to the last successful navigation. For the initial
navigation, this does not exist, so
''
/'/'
is used. Prior to thiscommit, the state reset was not also accompanied by a navigation to the
root of the application. This results in a "blank" screen (or rather, it
only shows content that is outside the
router-outlet
such as thestatic app header).
With this commit, the router initializer, which includes an
initialNavigation
call, now tracks whether the initial navigation succeeded (including
redirects). If the navigation did not succeed, a navigation to the root
of the application is triggered (
'/'
). Again, this is in addition towhat the router already does for this failed navigation: setting its internal
state and browser URL to the root.
Fixes #16211