@@ -107,10 +107,19 @@ export function genericHashLink(As) {
107
107
}
108
108
109
109
function handleClick ( e ) {
110
+ console . log ( 'HREER' , e . defaultPrevented , e ) ;
110
111
reset ( ) ;
111
112
hashFragment = props . elementId ? `#${ props . elementId } ` : linkHash ;
112
113
if ( props . onClick ) props . onClick ( e ) ;
113
- if ( hashFragment !== '' ) {
114
+ if (
115
+ hashFragment !== '' &&
116
+ // ignore non-vanilla click events, same as react-router
117
+ // below logic adapted from react-router: https://github.com/ReactTraining/react-router/blob/fc91700e08df8147bd2bb1be19a299cbb14dbcaa/packages/react-router-dom/modules/Link.js#L43-L48
118
+ ! e . defaultPrevented && // onClick prevented default
119
+ e . button === 0 && // ignore everything but left clicks
120
+ ( ! props . target || props . target === '_self' ) && // let browser handle "target=_blank" etc
121
+ ! ( e . metaKey || e . altKey || e . ctrlKey || e . shiftKey ) // ignore clicks with modifier keys
122
+ ) {
114
123
scrollFunction =
115
124
props . scroll ||
116
125
( ( el ) =>
@@ -136,7 +145,7 @@ export const NavHashLink = genericHashLink(NavLink);
136
145
if ( process . env . NODE_ENV !== 'production' ) {
137
146
HashLink . displayName = 'HashLink' ;
138
147
NavHashLink . displayName = 'NavHashLink' ;
139
-
148
+
140
149
const propTypes = {
141
150
onClick : PropTypes . func ,
142
151
children : PropTypes . node ,
@@ -145,7 +154,7 @@ if (process.env.NODE_ENV !== 'production') {
145
154
elementId : PropTypes . string ,
146
155
to : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
147
156
} ;
148
-
157
+
149
158
HashLink . propTypes = propTypes ;
150
159
NavHashLink . propTypes = propTypes ;
151
160
}
0 commit comments