Skip to content

Commit a1e5e74

Browse files
committed
Rearranged some more things 🚚
1 parent 7434af7 commit a1e5e74

File tree

1 file changed

+64
-71
lines changed

1 file changed

+64
-71
lines changed

upgrade-guides/v2.0.0.md

Lines changed: 64 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,9 @@ import { browserHistory } from 'react-router'
6060
<Router history={browserHistory} />
6161
```
6262

63-
## Changes to context and Mixins
63+
## Changes to `this.context`
6464

65-
Only an object named `router` is added to context. Accessing `this.context.history`, `this.context.location`, and `this.context.route` are all deprecated.
66-
67-
Additionally, since [`context` is now documented](https://facebook.github.io/react/docs/context.html), all mixins are deprecated as they simply served to conceal usage of context.
65+
Only an object named `router` is added to context. Accessing `this.context.history`, `this.context.location`, and `this.context.route` are all deprecated. This new object contains the methods available from `history` (such as `push`, `replace`) along with `setRouteLeaveHook`.
6866

6967
### Accessing location
7068

@@ -83,14 +81,58 @@ const RouteComponent = React.createClass({
8381
})
8482
```
8583

86-
## History Mixin
87-
(see below)
84+
## Mixins are deprecated
85+
86+
Since [`context` is now documented](https://facebook.github.io/react/docs/context.html), all mixins are deprecated as they simply served to conceal usage of context.
87+
88+
### `RouteContext` Mixin
89+
90+
```js
91+
// 1.x
92+
const RouteComponent = React.createClass({
93+
mixins: [ RouteContext ]
94+
})
8895

89-
## Route component `history` prop
90-
(see below)
96+
// 2.0.0
97+
const RouteComponent = React.createClass({
98+
contextTypes: {
99+
route: React.PropTypes.object
100+
},
101+
getChildContext() {
102+
return {
103+
route: this.props.route
104+
}
105+
}
106+
})
107+
```
91108

92-
## `context.history`
93-
(see below)
109+
### `Lifecycle` Mixin
110+
111+
```js
112+
// v1.0.x
113+
const RouteComponent = React.createClass({
114+
mixins: [ Lifecycle ],
115+
routerWillLeave() {
116+
// ...
117+
}
118+
})
119+
120+
// v2.0.0
121+
const RouteComponent = React.createClass({
122+
contextTypes: {
123+
router: object.isRequired
124+
},
125+
componentDidMount() {
126+
const { route } = this.props
127+
const { router } = this.context
128+
router.setRouteLeaveHook(route, this.routerWillLeave)
129+
}
130+
})
131+
```
132+
You don't need to manually tear down the route leave hook in most cases. We automatically remove all attached route leave hooks after leaving the associated route.
133+
134+
### History Mixin
135+
[See below](#navigating-inside-deeply-nested-components)
94136

95137
## Programatic Navigation
96138

@@ -131,7 +173,7 @@ class RouteComponent extends React.Component {
131173
}
132174
```
133175

134-
## Navigating inside deeply nested components
176+
### Navigating inside deeply nested components
135177

136178
```js
137179
// v1.0.x
@@ -164,32 +206,6 @@ const DeepComponent = React.createClass({
164206
}
165207
```
166208
167-
## Lifecycle Mixin
168-
169-
```js
170-
// v1.0.x
171-
const RouteComponent = React.createClass({
172-
mixins: [ Lifecycle ],
173-
routerWillLeave() {
174-
// ...
175-
}
176-
})
177-
178-
// v2.0.0
179-
const RouteComponent = React.createClass({
180-
contextTypes: {
181-
router: object.isRequired
182-
},
183-
componentDidMount() {
184-
const { route } = this.props
185-
const { router } = this.context
186-
router.setRouteLeaveHook(route, this.routerWillLeave)
187-
}
188-
})
189-
```
190-
191-
You don't need to manually tear down the route leave hook in most cases. We automatically remove all attached route leave hooks after leaving the associated route.
192-
193209
## `<Link to>` and `isActive` take location descriptors
194210
195211
`<Link to>` can now take a location descriptor in addition to strings. The `query` and `state` props are deprecated.
@@ -215,37 +231,6 @@ router.isActive(pathname, query, indexOnly)
215231
router.isActive({ pathname, query }, indexOnly)
216232
```
217233
218-
## `RoutingContext` renamed to `RouterContext`
219-
220-
```js
221-
// v1.0.x
222-
import { RoutingContext } from 'react-router'
223-
// v2.0.0
224-
import { RouterContext } from 'react-router'
225-
```
226-
227-
228-
## `RouteContext` Mixin
229-
230-
```js
231-
// 1.x
232-
const RouteComponent = React.createClass({
233-
mixins: [ RouteContext ]
234-
})
235-
236-
// 2.0.0
237-
const RouteComponent = React.createClass({
238-
contextTypes: {
239-
route: React.PropTypes.object
240-
},
241-
getChildContext() {
242-
return {
243-
route: this.props.route
244-
}
245-
}
246-
})
247-
```
248-
249234
## Custom Query String Parsing
250235
251236
```js
@@ -265,8 +250,18 @@ const appHistory = useRouterHistory({
265250

266251
<Router history={appHistory}/>
267252
```
253+
## Other Changes
268254
269-
## RoutingContext -> Router render prop
255+
### `RoutingContext` renamed to `RouterContext`
256+
257+
```js
258+
// v1.0.x
259+
import { RoutingContext } from 'react-router'
260+
// v2.0.0
261+
import { RouterContext } from 'react-router'
262+
```
263+
264+
### RoutingContext -> Router render prop
270265
271266
You can now pass a `render` prop to `Router` for it to use for rendering. This allows you to create "middleware components" that participate in routing. Its critical for integrations with libraries like Relay, Redux, Resolver, Transmit, Async Props, etc.
272267
@@ -276,5 +271,3 @@ You can now pass a `render` prop to `Router` for it to use for rendering. This a
276271
```
277272
278273
`RoutingContext` was undocumented and therefore has no backwards compatibility.
279-
280-

0 commit comments

Comments
 (0)