Skip to content

Commit e706133

Browse files
taiontimdorr
authored andcommitted
Fix when the <Link> onClick invariant runs (#3636)
1 parent e5c18c9 commit e706133

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

modules/Link.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,31 @@ const Link = React.createClass({
7474
},
7575

7676
handleClick(event) {
77+
if (this.props.onClick)
78+
this.props.onClick(event)
79+
80+
if (event.defaultPrevented)
81+
return
82+
7783
invariant(
7884
this.context.router,
79-
'<Link>s rendered outside of a router context cannot handle clicks.'
85+
'<Link>s rendered outside of a router context cannot navigate.'
8086
)
81-
82-
let allowTransition = true
83-
84-
if (this.props.onClick)
85-
this.props.onClick(event)
8687

8788
if (isModifiedEvent(event) || !isLeftClickEvent(event))
8889
return
8990

90-
if (event.defaultPrevented === true)
91-
allowTransition = false
92-
93-
// If target prop is set (e.g. to "_blank") let browser handle link.
91+
// If target prop is set (e.g. to "_blank"), let browser handle link.
9492
/* istanbul ignore if: untestable with Karma */
95-
if (this.props.target) {
96-
if (!allowTransition)
97-
event.preventDefault()
98-
93+
if (this.props.target)
9994
return
100-
}
10195

10296
event.preventDefault()
10397

104-
if (allowTransition) {
105-
const { to, query, hash, state } = this.props
106-
const location = createLocationDescriptor(to, { query, hash, state })
98+
const { to, query, hash, state } = this.props
99+
const location = createLocationDescriptor(to, { query, hash, state })
107100

108-
this.context.router.push(location)
109-
}
101+
this.context.router.push(location)
110102
},
111103

112104
render() {

0 commit comments

Comments
 (0)