Skip to content

Merge props passed to Link #170 #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 7, 2014
Merged
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
4 changes: 4 additions & 0 deletions docs/api/components/Link.md
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ name through the link's properties to the resulting url.
The className a `Link` receives when it's route is active. Defaults to
`active`.

### *others*

You can also pass props you'd like to be on the `<a>` such as a title, id, or className.

Example
-------

9 changes: 8 additions & 1 deletion modules/components/Link.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ var ActiveState = require('../mixins/ActiveState');
var withoutProperties = require('../helpers/withoutProperties');
var transitionTo = require('../helpers/transitionTo');
var makeHref = require('../helpers/makeHref');

var hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
Copy link
Member

Choose a reason for hiding this comment

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

clever, never done it like this before

/**
* A map of <Link> component props that are reserved for use by the
* router and/or React. All other props are used as params that are
@@ -124,6 +124,13 @@ var Link = React.createClass({
onClick: this.handleClick
};

// pull in props without overriding
for (var propName in this.props) {
if (hasOwn(this.props, propName) && hasOwn(props, propName) === false) {
props[propName] = this.props[propName];
}
}

return React.DOM.a(props, this.props.children);
}