-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[changed]
<Link/>
s to take params property
- old behavior is maintained, but logs a deprecation warning - instead of passing in properties to fill in the dynamic segments, we just take it from the params object closes #217
- Loading branch information
1 parent
1fcf686
commit 8d2f3ed
Showing
8 changed files
with
68 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ var withoutProperties = require('../helpers/withoutProperties'); | |
var transitionTo = require('../helpers/transitionTo'); | ||
var hasOwnProperty = require('../helpers/hasOwnProperty'); | ||
var makeHref = require('../helpers/makeHref'); | ||
var warning = require('react/lib/warning'); | ||
|
||
function isLeftClickEvent(event) { | ||
return event.button === 0; | ||
|
@@ -14,7 +15,7 @@ function isModifiedEvent(event) { | |
} | ||
|
||
/** | ||
* A map of <Link> component props that are reserved for use by the | ||
* DEPRECATED: 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 | ||
* interpolated into the link's path. | ||
*/ | ||
|
@@ -38,12 +39,12 @@ var RESERVED_PROPS = { | |
* | ||
* You could use the following component to link to that route: | ||
* | ||
* <Link to="showPost" postId="123"/> | ||
* <Link to="showPost" params={{postId: "123"}} /> | ||
* | ||
* In addition to params, links may pass along query string parameters | ||
* using the `query` prop. | ||
* | ||
* <Link to="showPost" postId="123" query={{show:true}}/> | ||
* <Link to="showPost" params={{postId: "123"}} query={{show:true}}/> | ||
*/ | ||
var Link = React.createClass({ | ||
|
||
|
@@ -53,15 +54,29 @@ var Link = React.createClass({ | |
|
||
statics: { | ||
|
||
// TODO: Deprecate passing props as params in v1.0 | ||
getUnreservedProps: function (props) { | ||
warning( | ||
false, | ||
'Passing props for params on <Link>s is deprecated, '+ | ||
'please use the `params` property.' | ||
); | ||
return withoutProperties(props, RESERVED_PROPS); | ||
}, | ||
|
||
/** | ||
* Returns a hash of URL parameters to use in this <Link>'s path. | ||
*/ | ||
getParams: function (props) { | ||
return props.params || Link.getUnreservedProps(props); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ryanflorence
via email
Author
Member
|
||
} | ||
|
||
}, | ||
|
||
propTypes: { | ||
to: React.PropTypes.string.isRequired, | ||
activeClassName: React.PropTypes.string.isRequired, | ||
params: React.PropTypes.object, | ||
query: React.PropTypes.object, | ||
onClick: React.PropTypes.func | ||
}, | ||
|
@@ -78,18 +93,11 @@ var Link = React.createClass({ | |
}; | ||
}, | ||
|
||
/** | ||
* Returns a hash of URL parameters to use in this <Link>'s path. | ||
*/ | ||
getParams: function () { | ||
return Link.getUnreservedProps(this.props); | ||
}, | ||
|
||
/** | ||
* Returns the value of the "href" attribute to use on the DOM element. | ||
*/ | ||
getHref: function () { | ||
return makeHref(this.props.to, this.getParams(), this.props.query); | ||
return makeHref(this.props.to, Link.getParams(this.props), this.props.query); | ||
}, | ||
|
||
/** | ||
|
@@ -106,7 +114,7 @@ var Link = React.createClass({ | |
}, | ||
|
||
componentWillReceiveProps: function (nextProps) { | ||
var params = Link.getUnreservedProps(nextProps); | ||
var params = Link.getParams(nextProps); | ||
|
||
this.setState({ | ||
isActive: Link.isActive(nextProps.to, params, nextProps.query) | ||
|
@@ -115,7 +123,7 @@ var Link = React.createClass({ | |
|
||
updateActiveState: function () { | ||
this.setState({ | ||
isActive: Link.isActive(this.props.to, this.getParams(), this.props.query) | ||
isActive: Link.isActive(this.props.to, Link.getParams(this.props), this.props.query) | ||
}); | ||
}, | ||
|
||
|
@@ -135,7 +143,7 @@ var Link = React.createClass({ | |
event.preventDefault(); | ||
|
||
if (allowTransition) | ||
transitionTo(this.props.to, this.getParams(), this.props.query); | ||
transitionTo(this.props.to, Link.getParams(this.props), this.props.query); | ||
}, | ||
|
||
render: function () { | ||
|
Doesn't this mean that any Link component without a "param" prop will get the warning specified in
getUnreservedProps()
? I'm seeing a lot of these warnings for fairly innocuous-looking Link components (<Link to="editor" />
, etc).