2
2
3
3
### Changes to context exports and Mixins
4
4
5
- Only an object named ` router ` is added to context. Accessing ` context.history ` , ` context.location ` , and ` context.route ` are all deprecated.
5
+ Only an object named ` router ` is added to context. Accessing ` context.history ` ,
6
+ ` context.location ` , and ` context.route ` are all deprecated.
6
7
7
8
Additionally, since ` context ` is now documented, all mixins are deprecated.
8
9
@@ -31,32 +32,55 @@ it's up to you.
31
32
32
33
#### Navigating
33
34
34
- In all cases where you once had a ` history ` for navigation, you now have a ` router ` to navigate instead.
35
+ In all cases where you once had a ` history ` for navigation, you now have a
36
+ ` router ` to navigate instead.
35
37
36
38
``` js
37
- // v1.0.0
39
+ // v1.0.x
38
40
history .pushState (state, path, query)
39
41
history .replaceState (state, path, query)
40
42
41
- // v1.1 .0
43
+ // v2.0 .0
42
44
router .push (path)
43
- router .push ({ path , query, state }) // new "location descriptor"
45
+ router .push ({ pathname , query, state }) // new "location descriptor"
44
46
45
47
router .replace (path)
46
- router .replace ({ path, query, state }) // new "location descriptor"
48
+ router .replace ({ pathname, query, state }) // new "location descriptor"
49
+ ```
50
+
51
+ #### Links
52
+
53
+ ` <Link to> ` s now takes a location descriptor. The other props are deprecated.
54
+
55
+ ``` js
56
+ // v1.0.x
57
+ < Link to= " /foo" query= {{ the: ' query' }}>
58
+
59
+ // v2.0.0
60
+ < Link to= {{ pathname: ' /foo' , query: { the: ' query' } }}>
61
+ ```
62
+
63
+ For custom link-like components, the same applies for ` router.isActive ` .
64
+
65
+ ``` js
66
+ // v1.0.x
67
+ router .isActive (pathname, query, indexOnly)
68
+
69
+ // v2.0.0
70
+ router .isActive ({ pathname, query }, indexOnly)
47
71
```
48
72
49
73
#### Navigating in route components
50
74
51
75
``` js
52
- // v1.0.0
76
+ // v1.0.x
53
77
class RouteComponent extends React .Component {
54
78
someHandler () {
55
79
this .props .history .pushState (... )
56
80
}
57
81
}
58
82
59
- // v1.1 .0
83
+ // v2.0 .0
60
84
class RouteComponent extends React .Component {
61
85
someHandler () {
62
86
this .props .router .push (... )
@@ -67,7 +91,7 @@ class RouteComponent extends React.Component {
67
91
#### Navigating inside deeply nested components
68
92
69
93
``` js
70
- // v1.0.0
94
+ // v1.0.x
71
95
const DeepComponent = React .createClass ({
72
96
mixins: [ History ],
73
97
@@ -76,7 +100,7 @@ const DeepComponent = React.createClass({
76
100
}
77
101
}
78
102
79
- // v1.1 .0
103
+ // v2.0 .0
80
104
// You have a couple options:
81
105
// Use context directly (recommended)
82
106
const DeepComponent = React .createClass ({
@@ -119,15 +143,15 @@ const DeepComponent = React.createClass({
119
143
#### Lifecycle Mixin with route components
120
144
121
145
` ` ` js
122
- // v1.0.0
146
+ // v1.0.x
123
147
const RouteComponent = React .createClass ({
124
148
mixins: [ Lifecycle ],
125
149
routerWillLeave () {
126
150
// ...
127
151
}
128
152
})
129
153
130
- // v1.1 .0
154
+ // v2.0 .0
131
155
const RouteComponent = React .createClass ({
132
156
componentDidMount () {
133
157
const { router , route } = this .props
@@ -138,18 +162,22 @@ const RouteComponent = React.createClass({
138
162
// or make your own mixin, check it out in the next section
139
163
` ` `
140
164
165
+ You don't need to manually tear down the route leave hook in most cases any
166
+ more. We automatically remove all attached route leave hooks after leaving the
167
+ associated route.
168
+
141
169
#### Lifecycle Mixin with deep, non-route components
142
170
143
171
` ` ` js
144
- // v1.0.0
172
+ // v1.0.x
145
173
const DeepComponent = React .createClass ({
146
174
mixins: [ Lifecycle ],
147
175
routerWillLeave () {
148
176
// do stuff
149
177
}
150
178
})
151
179
152
- // v1.1 .0
180
+ // v2.0 .0
153
181
// you have a couple of options
154
182
// first you can put the route on context in the route component
155
183
const RouteComponent = React .createClass ({
@@ -201,7 +229,7 @@ Just a stub so we don't forget to talk about it.
201
229
` ` ` js
202
230
// v1.0.x
203
231
import { RoutingContext } from ' react-router'
204
- // v1.1 .0
232
+ // v2.0 .0
205
233
import { RouterContext } from ' react-router'
206
234
` ` `
207
235
0 commit comments