From 66ae831311d88046204242bc8e95d3ab90156971 Mon Sep 17 00:00:00 2001 From: woodcutter Date: Mon, 29 Jul 2019 17:34:04 +0500 Subject: [PATCH] fix(Link): fix alt key press and event preventDefault --- package.json | 2 +- src/components/Link.js | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f082ac2..7332021 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/components/Link.js b/src/components/Link.js index b6a6f9e..8c43a2f 100644 --- a/src/components/Link.js +++ b/src/components/Link.js @@ -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) {