@@ -4,6 +4,7 @@ var withoutProperties = require('../helpers/withoutProperties');
4
4
var transitionTo = require ( '../helpers/transitionTo' ) ;
5
5
var hasOwnProperty = require ( '../helpers/hasOwnProperty' ) ;
6
6
var makeHref = require ( '../helpers/makeHref' ) ;
7
+ var warning = require ( 'react/lib/warning' ) ;
7
8
8
9
function isLeftClickEvent ( event ) {
9
10
return event . button === 0 ;
@@ -14,7 +15,7 @@ function isModifiedEvent(event) {
14
15
}
15
16
16
17
/**
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
18
19
* router and/or React. All other props are used as params that are
19
20
* interpolated into the link's path.
20
21
*/
@@ -38,12 +39,12 @@ var RESERVED_PROPS = {
38
39
*
39
40
* You could use the following component to link to that route:
40
41
*
41
- * <Link to="showPost" postId= "123"/>
42
+ * <Link to="showPost" params={{postId: "123"}} />
42
43
*
43
44
* In addition to params, links may pass along query string parameters
44
45
* using the `query` prop.
45
46
*
46
- * <Link to="showPost" postId= "123" query={{show:true}}/>
47
+ * <Link to="showPost" params={{postId: "123"}} query={{show:true}}/>
47
48
*/
48
49
var Link = React . createClass ( {
49
50
@@ -53,15 +54,29 @@ var Link = React.createClass({
53
54
54
55
statics : {
55
56
57
+ // TODO: Deprecate passing props as params in v1.0
56
58
getUnreservedProps : function ( props ) {
59
+ warning (
60
+ false ,
61
+ 'Passing props for params on <Link>s is deprecated, ' +
62
+ 'please use the `params` property.'
63
+ ) ;
57
64
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 ) ;
58
72
}
59
73
60
74
} ,
61
75
62
76
propTypes : {
63
77
to : React . PropTypes . string . isRequired ,
64
78
activeClassName : React . PropTypes . string . isRequired ,
79
+ params : React . PropTypes . object ,
65
80
query : React . PropTypes . object ,
66
81
onClick : React . PropTypes . func
67
82
} ,
@@ -78,18 +93,11 @@ var Link = React.createClass({
78
93
} ;
79
94
} ,
80
95
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
-
88
96
/**
89
97
* Returns the value of the "href" attribute to use on the DOM element.
90
98
*/
91
99
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 ) ;
93
101
} ,
94
102
95
103
/**
@@ -106,7 +114,7 @@ var Link = React.createClass({
106
114
} ,
107
115
108
116
componentWillReceiveProps : function ( nextProps ) {
109
- var params = Link . getUnreservedProps ( nextProps ) ;
117
+ var params = Link . getParams ( nextProps ) ;
110
118
111
119
this . setState ( {
112
120
isActive : Link . isActive ( nextProps . to , params , nextProps . query )
@@ -115,7 +123,7 @@ var Link = React.createClass({
115
123
116
124
updateActiveState : function ( ) {
117
125
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 )
119
127
} ) ;
120
128
} ,
121
129
@@ -135,7 +143,7 @@ var Link = React.createClass({
135
143
event . preventDefault ( ) ;
136
144
137
145
if ( allowTransition )
138
- transitionTo ( this . props . to , this . getParams ( ) , this . props . query ) ;
146
+ transitionTo ( this . props . to , Link . getParams ( this . props ) , this . props . query ) ;
139
147
} ,
140
148
141
149
render : function ( ) {
0 commit comments