fix(angular): honor modifier-click on routerLink#31230
Open
ShaneK wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue number: resolves #26394
What is the current behavior?
When
routerLinkis applied to a non-anchor Ionic component (ion-item,ion-button),RouterLinkDelegateDirectivealways routes in-app on click. A ctrl/meta/shift click, or a host withtarget="_blank", gets swallowed by the in-app navigation, so the browser never opens the link in a new tab. A plain<a routerLink>honors these intents, but the Ionic delegate doesn't, even though these components render a native anchor in their shadow DOM that's capable of the native new-tab behavior.What is the new behavior?
RouterLinkDelegateDirectivenow adds a capture-phase click listener so it runs before Angular'sRouterLinkhandler and the directive's own bubble-phaseonClick. When the click is a new-tab intent (a ctrl/meta/shift modifier is held, or the hosttargetis set to anything other than_self), it callsstopImmediatePropagation()to cancel the in-app navigation but leavespreventDefaultalone, so the shadow-DOM anchor can still open the tab. Normal clicks are unaffected and continue to navigate in-app. The listener is removed inngOnDestroy.Does this introduce a breaking change?
Other information
To verify manually in the Angular preview, ctrl/cmd-click the two
ion-itemrows (a plain one and atarget="_blank"one) and confirm each opens a new tab instead of navigating in place:https://ionic-framework-git-fix-angular-routerlink-modifi-896c58-ionic1.vercel.app/angular/standalone/router-link
If you compare that against the main version of the same component, you'll be able to see how it's fixed:
https://ionic-framework-git-main-ionic1.vercel.app/angular/standalone/router-link