Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api/components/Link.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ name through the link's properties to the resulting url.
The className a `Link` receives when it's route is active. Defaults to
`active`.

### `onClick`

A custom handler for the click event. Works just like a handler on an `<a>`
tag - calling `e.preventDefault()` or returning `false` will prevent the
transition from firing, while `e.stopPropagation()` will prevent the event
from bubbling.

### *others*

You can also pass props you'd like to be on the `<a>` such as a title, id, or className.
Expand Down
17 changes: 14 additions & 3 deletions modules/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var Link = React.createClass({
propTypes: {
to: React.PropTypes.string.isRequired,
activeClassName: React.PropTypes.string.isRequired,
query: React.PropTypes.object
query: React.PropTypes.object,
onClick: React.PropTypes.func
},

getDefaultProps: function () {
Expand Down Expand Up @@ -108,13 +109,23 @@ var Link = React.createClass({
});
},

handleClick: function (event) {
handleClick: function(event) {
var allowTransition = true;
var ret;

if (this.props.onClick)
ret = this.props.onClick(event);

if (isModifiedEvent(event) || !isLeftClick(event))
return;

if (ret === false || event.preventDefaulted === true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

um, defaultPrevented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/facepalm I should have caught that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allowTransition = false;

event.preventDefault();

transitionTo(this.props.to, this.getParams(), this.props.query);
if (allowTransition)
transitionTo(this.props.to, this.getParams(), this.props.query);
},

render: function () {
Expand Down