Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(router): Align RouterModule.forRoot errorHandler with provider error handler #57050

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

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Jul 19, 2024

This change aligns the behavior of the error handler in the ExtraOptions of RouterModule.forRoot with the error handler in withNavigationErrorHandler. The changes are:

  • Slightly different timing: The handler is called before the NavigationError emits
  • Runs in the injection context, meaning it is more configurable at the config location rather than needing to assign the value to the Router.errorHandler later to get access to injectables
  • Can now return RedirectCommand to recover from the error and redirect without emitting NavigationError
  • No longer allows arbitrarily overriding return value of the navigation promise

BREAKING CHANGE: The Router.errorHandler property has been removed. Adding an error handler should be configured in either withNavigationErrorHandler with provideRouter or the errorHandler property in the extra options of RouterModule.forRoot. In addition, the error handler cannot be used to change the return value of the router navigation promise or prevent it from rejecting. Instead, if you want to prevent the promise from rejecting, use resolveNavigationPromiseOnError.

@atscott atscott added breaking changes area: router target: major This PR is targeted for the next major release labels Jul 19, 2024
@ngbot ngbot bot added this to the Backlog milestone Jul 19, 2024
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Jul 19, 2024
@pullapprove pullapprove bot requested a review from AndrewKushnir August 1, 2024 15:34
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@atscott atscott added the action: global presubmit The PR is in need of a google3 global presubmit label Aug 1, 2024
@atscott
Copy link
Contributor Author

atscott commented Aug 5, 2024

TGP is green with local changes needed from cl/658542550

@atscott atscott removed the action: global presubmit The PR is in need of a google3 global presubmit label Aug 5, 2024
…ror handler

This change aligns the behavior of the error handler in the
`ExtraOptions` of `RouterModule.forRoot` with the error handler in
`withNavigationErrorHandler`. The changes are:

* Slightly different timing: The handler is called before the
  `NavigationError` emits
* Runs in the injection context, meaning it is more configurable at the
  config location rather than needing to assign the value to the
  `Router.errorHandler` later to get access to injectables
* Can now return `RedirectCommand` to recover from the error and
  redirect without emitting `NavigationError`
* No longer allows arbitrarily overriding return value of the navigation
  promise

BREAKING CHANGE: The `Router.errorHandler` property has been removed.
Adding an error handler should be configured in either
`withNavigationErrorHandler` with `provideRouter` or the `errorHandler`
property in the extra options of `RouterModule.forRoot`. In addition,
the error handler cannot be used to change the return value of the
router navigation promise or prevent it from rejecting. Instead, if you
want to prevent the promise from rejecting, use `resolveNavigationPromiseOnError`.
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

🎉 for cleaning up deprecations!

@atscott atscott added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: merge The PR is ready for merge by the caretaker labels Aug 8, 2024
@atscott
Copy link
Contributor Author

atscott commented Aug 8, 2024

caretaker note: please patch in the changes to the ssr router in cl/658542550

@AndrewKushnir AndrewKushnir added target: minor This PR is targeted for the next minor release target: major This PR is targeted for the next major release and removed target: major This PR is targeted for the next major release target: minor This PR is targeted for the next minor release labels Aug 8, 2024
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit b279081.

The changes were merged into the following branches: main

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: router breaking changes detected: breaking change PR contains a commit with a breaking change merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants