You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only an object named `router` is added to context. Accessing `context.history`,
6
-
`context.location`, and `context.route` are all deprecated.
5
+
#### Goals of this release
7
6
8
-
Additionally, since `context` is now documented, all mixins are deprecated.
7
+
1. Clear up the coupling between History and Router with sipler APIs.
8
+
9
+
2. Provide cleaner integrations with other libraries like Redux, Relay, Async Props etc.
10
+
11
+
3. Stop providing API that conceals usage of `context`. It is now a documented feature of React so developers using Router can implement their own opinions on how best to use context: Mixins, higher-order components, decorators, etc. React Router no longer has an opinion, but instead uses the lowest level feature of React. This project wants to be an incredibly useful routing library and doesn't want to get hung up on best-practice patterns for getting stuff from up top to down low.
12
+
13
+
#### Backwards Compatibility and Deprecation Warnings
14
+
15
+
This has been a community project from the start, we need your help making the upgrade as smooth as possible for everybody!
16
+
17
+
We have done our best to provide backwards compatibility with deprecated APIs. If you drop in v2.x into a v1.x application and it doesn't run, then there is a bug. Please open an issue when you discover what the problem is so we can get a fix out.
18
+
19
+
The deprecation warnings should also lead you to the relevant part of this document. If one doesn't, please open a pull request with a fix. Also, if any part of this document could be improved, please let us know how. Confound it, our bias is often inescapable!
20
+
21
+
### New Router render prop (`RoutingContext` prop replacement)
22
+
23
+
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.
Though you may want to hide that in a mixin or higher order component,
31
-
it's up to you.
58
+
### History Mixin
59
+
(see below)
32
60
33
-
#### Navigating
61
+
### Route component `history` prop
62
+
(see below)
34
63
35
-
In all cases where you once had a `history` for navigation, you now have a
36
-
`router` to navigate instead.
64
+
### `context.history`
65
+
(see below)
66
+
67
+
### Programatic Navigation
68
+
69
+
There were several ways to get a hold of the history object to navigate around (see above :P) 1.0. In 2.0, where you once had a `history`, you now have a `router` to navigate instead (only from context) with a better signature.
37
70
38
71
```js
39
72
// v1.0.x
@@ -48,29 +81,7 @@ router.replace(path)
48
81
router.replace({ pathname, query, state }) // new "location descriptor"
49
82
```
50
83
51
-
#### Links
52
-
53
-
`<Link to>`s now takes a location descriptor. The other props are deprecated.
// or make your own mixin, check it out in the next section
163
161
```
164
162
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.
163
+
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.
164
+
165
+
### Links `to` Type
168
166
169
-
#### Lifecycle Mixin with deep, non-route components
167
+
`<Link to>` can now take a location descriptor in addition to strings. The `query` and `state` props are deprecated.
170
168
171
169
```js
172
170
// v1.0.x
173
-
constDeepComponent=React.createClass({
174
-
mixins: [ Lifecycle ],
175
-
routerWillLeave() {
176
-
// do stuff
177
-
}
178
-
})
171
+
<Link to="/foo" query={{ the:'query' }}/>
179
172
180
173
// v2.0.0
181
-
// you have a couple of options
182
-
// first you can put the route on context in the route component
Copy file name to clipboardExpand all lines: docs/API.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,8 @@ Called whenever the router updates its state in response to URL changes.
85
85
##### `render(props)`
86
86
This is primarily for integrating with other libraries that need to participate in rendering before the route components are rendered. It defaults to `render={(props) => <RouterContext {...props}/>}`.
87
87
88
+
Ensure that you render a `RouterContext` at the end of the line, passing all the props passed to `render`.
89
+
88
90
89
91
#### Examples
90
92
Please see the [`examples/`](/examples) directory of the repository for extensive examples of using `Router`.
0 commit comments