Skip to content

Commit

Permalink
fix(Link): fix alt key press and event preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcutter committed Jul 29, 2019
1 parent a2aeb82 commit 66ae831
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-unity-router",
"version": "1.6.0",
"version": "1.6.1",
"description": "Redux router that syncs history with store",
"main": "dist/index.js",
"scripts": {
Expand Down
22 changes: 16 additions & 6 deletions src/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,39 @@ class Link extends BaseRouterComponent {
initiateLocationChange(e) {
const { target } = this.props;

if (!target && !this.href.protocol && (e.nativeEvent && e.nativeEvent.which) !== 2 && !e.metaKey && !e.ctrlKey) {
if (!target &&
!e.altKey &&
!e.metaKey &&
!e.ctrlKey &&
!this.href.protocol &&
(e.nativeEvent && e.nativeEvent.which) !== 2
) {
e.preventDefault();
this.locationChange(this.href);
}
}

handleClick(e) {

const { onClick } = this.props;

if (typeof onClick === 'function') {

const onClickResult = onClick(e);

if (typeof onClickResult === 'object' && typeof onClickResult.then === 'function') {
if (typeof onClickResult === 'object' &&
typeof onClickResult.then === 'function') {
e.persist();

return onClickResult.then(() => {
this.initiateLocationChange(e);
if (!e.defaultPrevented) {
this.initiateLocationChange(e);
}
});
}
}

return this.initiateLocationChange(e);
if (!e.defaultPrevented) {
return this.initiateLocationChange(e);
}
}

getHref(props) {
Expand Down

0 comments on commit 66ae831

Please sign in to comment.