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

Skip to content

feat(router): Add ability to directly abort a navigation #60380

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 Mar 13, 2025

This commit adds the ability to directly abort a navigation through the
Router.getCurrentNavigation()?.abort() method. While there are no
feature requests for this, it is a feature that will be necessary for
integration with the navigation API. The API enables better tracking of
an ongoing navigation for SPAs and a site visitor can cancel a
navigation by clicking the stop button in the browser. While this could
technically be done on the transition with an internal jsdoc comment to
hide it from application developers, there's no need.

With this feature, I believe it would be possible to create somewhat of a shim
to integrate with the navigation API even before the router has full support
using the router events to control a deferred navigation that never
commits the URL and always aborts itself on navigation end.

@atscott atscott added area: router target: minor This PR is targeted for the next minor release labels Mar 13, 2025
@ngbot ngbot bot added this to the Backlog milestone Mar 13, 2025
@angular-robot angular-robot bot added the detected: feature PR contains a feature commit label Mar 13, 2025
Copy link
Contributor

@thePunderWoman thePunderWoman 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: fw-general, public-api

Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: public-api

* Aborts the navigation if it has not yet been completed or reached the point where routes are being activated.
* This function is a no-op if the navigation is beyond the point where it can be aborted.
*/
readonly abort: () => void;
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way for us to indicate whether the abort was successful or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was kind of treating it like a promise that’s settled (resolving or rejecting after is just ignored), a signal that’s aborted twice (second one is ignored), or a signal that aborts after a fetch already completes. Success or failure of the abort can be determined more or less from the router state and/or events.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devversion Does that seem reasonable or should we brainstorm other ways to determine if the abort "succeeded"?

Copy link
Member

@devversion devversion Mar 27, 2025

Choose a reason for hiding this comment

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

I'm good with that. We can always expand if there are use-cases I imagine.

Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: public-api

@atscott atscott added state: blocked requires: TGP This PR requires a passing TGP before merging is allowed labels Mar 28, 2025
@pullapprove pullapprove bot removed the requires: TGP This PR requires a passing TGP before merging is allowed label Mar 28, 2025
@atscott
Copy link
Contributor Author

atscott commented Mar 28, 2025

Adding blocked label. Tests are spying on and returning values for getCurrentNavigation...

This commit adds the ability to directly abort a navigation through the
`Router.getCurrentNavigation()?.abort()` method. While there are no
feature requests for this, it is a feature that will be necessary for
integration with the navigation API. The API enables better tracking of
an ongoing navigation for SPAs and a site visitor can cancel a
navigation by clicking the stop button in the browser. While this could
technically be done on the transition with an internal jsdoc comment to
hide it from application developers, there's no need.

With this feature, I believe it would be possible to create somewhat of a shim
to integrate with the navigation API even before the router has full support
using the router events to control a deferred navigation that never
commits the URL and always aborts itself on navigation end.
@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed target: minor This PR is targeted for the next minor release labels Apr 2, 2025
@thePunderWoman thePunderWoman removed the request for review from alxhub April 2, 2025 16:34
@thePunderWoman thePunderWoman added target: major This PR is targeted for the next major release and removed state: blocked labels Apr 2, 2025
@atscott
Copy link
Contributor Author

atscott commented Apr 2, 2025

TGP

@thePunderWoman thePunderWoman added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Apr 2, 2025
@thePunderWoman
Copy link
Contributor

Caretaker note: this has a TGP and is safe to merge.

@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 0bb4bd6.

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 May 3, 2025
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 detected: feature PR contains a feature commit 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.

4 participants