Skip to content

Commit 97d2c4b

Browse files
author
woodcutter
committed
fix(Link): fix alt key press and event preventDefault
1 parent a2aeb82 commit 97d2c4b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-unity-router",
3-
"version": "1.6.0",
3+
"version": "1.6.1",
44
"description": "Redux router that syncs history with store",
55
"main": "dist/index.js",
66
"scripts": {

src/components/Link.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,39 @@ class Link extends BaseRouterComponent {
6363
initiateLocationChange(e) {
6464
const { target } = this.props;
6565

66-
if (!target && !this.href.protocol && (e.nativeEvent && e.nativeEvent.which) !== 2 && !e.metaKey && !e.ctrlKey) {
66+
if (!target &&
67+
!e.altKey &&
68+
!e.metaKey &&
69+
!e.ctrlKey &&
70+
!this.href.protocol &&
71+
(e.nativeEvent && e.nativeEvent.which) !== 2
72+
) {
6773
e.preventDefault();
6874
this.locationChange(this.href);
6975
}
7076
}
7177

7278
handleClick(e) {
73-
7479
const { onClick } = this.props;
7580

7681
if (typeof onClick === 'function') {
77-
7882
const onClickResult = onClick(e);
7983

80-
if (typeof onClickResult === 'object' && typeof onClickResult.then === 'function') {
84+
if (typeof onClickResult === 'object' &&
85+
typeof onClickResult.then === 'function') {
8186
e.persist();
87+
8288
return onClickResult.then(() => {
83-
this.initiateLocationChange(e);
89+
if (!e.defaultPrevented) {
90+
this.initiateLocationChange(e);
91+
}
8492
});
8593
}
8694
}
8795

88-
return this.initiateLocationChange(e);
96+
if (!e.defaultPrevented) {
97+
return this.initiateLocationChange(e);
98+
}
8999
}
90100

91101
getHref(props) {

0 commit comments

Comments
 (0)