@@ -4,6 +4,7 @@ var withoutProperties = require('../helpers/withoutProperties');
44var transitionTo = require ( '../helpers/transitionTo' ) ;
55var hasOwnProperty = require ( '../helpers/hasOwnProperty' ) ;
66var makeHref = require ( '../helpers/makeHref' ) ;
7+ var warning = require ( 'react/lib/warning' ) ;
78
89function isLeftClickEvent ( event ) {
910 return event . button === 0 ;
@@ -14,7 +15,7 @@ function isModifiedEvent(event) {
1415}
1516
1617/**
17- * A map of <Link> component props that are reserved for use by the
18+ * DEPRECATED: A map of <Link> component props that are reserved for use by the
1819 * router and/or React. All other props are used as params that are
1920 * interpolated into the link's path.
2021 */
@@ -38,12 +39,12 @@ var RESERVED_PROPS = {
3839 *
3940 * You could use the following component to link to that route:
4041 *
41- * <Link to="showPost" postId= "123"/>
42+ * <Link to="showPost" params={{postId: "123"}} />
4243 *
4344 * In addition to params, links may pass along query string parameters
4445 * using the `query` prop.
4546 *
46- * <Link to="showPost" postId= "123" query={{show:true}}/>
47+ * <Link to="showPost" params={{postId: "123"}} query={{show:true}}/>
4748 */
4849var Link = React . createClass ( {
4950
@@ -53,15 +54,29 @@ var Link = React.createClass({
5354
5455 statics : {
5556
57+ // TODO: Deprecate passing props as params in v1.0
5658 getUnreservedProps : function ( props ) {
59+ warning (
60+ false ,
61+ 'Passing props for params on <Link>s is deprecated, ' +
62+ 'please use the `params` property.'
63+ ) ;
5764 return withoutProperties ( props , RESERVED_PROPS ) ;
65+ } ,
66+
67+ /**
68+ * Returns a hash of URL parameters to use in this <Link>'s path.
69+ */
70+ getParams : function ( props ) {
71+ return props . params || Link . getUnreservedProps ( props ) ;
5872 }
5973
6074 } ,
6175
6276 propTypes : {
6377 to : React . PropTypes . string . isRequired ,
6478 activeClassName : React . PropTypes . string . isRequired ,
79+ params : React . PropTypes . object ,
6580 query : React . PropTypes . object ,
6681 onClick : React . PropTypes . func
6782 } ,
@@ -78,18 +93,11 @@ var Link = React.createClass({
7893 } ;
7994 } ,
8095
81- /**
82- * Returns a hash of URL parameters to use in this <Link>'s path.
83- */
84- getParams : function ( ) {
85- return Link . getUnreservedProps ( this . props ) ;
86- } ,
87-
8896 /**
8997 * Returns the value of the "href" attribute to use on the DOM element.
9098 */
9199 getHref : function ( ) {
92- return makeHref ( this . props . to , this . getParams ( ) , this . props . query ) ;
100+ return makeHref ( this . props . to , Link . getParams ( this . props ) , this . props . query ) ;
93101 } ,
94102
95103 /**
@@ -106,7 +114,7 @@ var Link = React.createClass({
106114 } ,
107115
108116 componentWillReceiveProps : function ( nextProps ) {
109- var params = Link . getUnreservedProps ( nextProps ) ;
117+ var params = Link . getParams ( nextProps ) ;
110118
111119 this . setState ( {
112120 isActive : Link . isActive ( nextProps . to , params , nextProps . query )
@@ -115,7 +123,7 @@ var Link = React.createClass({
115123
116124 updateActiveState : function ( ) {
117125 this . setState ( {
118- isActive : Link . isActive ( this . props . to , this . getParams ( ) , this . props . query )
126+ isActive : Link . isActive ( this . props . to , Link . getParams ( this . props ) , this . props . query )
119127 } ) ;
120128 } ,
121129
@@ -135,7 +143,7 @@ var Link = React.createClass({
135143 event . preventDefault ( ) ;
136144
137145 if ( allowTransition )
138- transitionTo ( this . props . to , this . getParams ( ) , this . props . query ) ;
146+ transitionTo ( this . props . to , Link . getParams ( this . props ) , this . props . query ) ;
139147 } ,
140148
141149 render : function ( ) {
0 commit comments