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
Copy file name to clipboardExpand all lines: upgrade-guides/v2.0.0.md
+19-14Lines changed: 19 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,11 +24,17 @@ We have done our best to provide backwards compatibility with deprecated APIs. I
24
24
25
25
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!
26
26
27
-
## Router`history`prop
27
+
## Using`history`with `Router`
28
28
29
-
### Default Hash History
29
+
### History singletons provided
30
30
31
-
`Router` used to default to creating a hash history, it no longer creates a default, you must provide one. This helps keep your app's bundle size down by not including hash history no matter what history you're actually using.
31
+
We now include singleton `history` instances for you to use in the router. They are `hashHistory` (hash-based URLs) and `browserHistory` (HTML5 pushState "pretty" URLs). They include any needed history wrappers (such as `useQueries`) so you don't have to write as much boilerplate as before.
32
+
33
+
Another big change because of this is `history` is now a normal dependency. You no longer have to install and maintain `history` spearately. Batteries included!
34
+
35
+
### No Default History
36
+
37
+
`Router` used to default to creating a hash history. It no longer creates a default, you must provide one. This helps keep your app's bundle size down by not including hash history no matter what history you're actually using.
32
38
33
39
```js
34
40
// v1.x
@@ -37,33 +43,32 @@ The deprecation warnings should also lead you to the relevant part of this docum
37
43
// v2.0.0
38
44
// hash history
39
45
import { hashHistory } from'react-router'
40
-
<Router history={hashHistory}/>
46
+
<Router history={hashHistory}/>
41
47
```
42
48
43
-
### Using Browser History
49
+
### Using Browser (HTML5 pushState) History
50
+
51
+
As already mentioned, you now use the singleton `browserHistory` exported from `react-router`.
Only an object named `router` is added to context. Accessing `context.history`, `context.location`, and `context.route` are all deprecated.
65
+
Only an object named `router` is added to context. Accessing `this.context.history`, `this.context.location`, and `this.context.route` are all deprecated.
58
66
59
-
Additionally, since `context` is now documented, all mixins are deprecated as they simply served to conceal usage of context.
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.
60
68
61
69
### Accessing location
62
70
63
-
Access `location` from `this.props.location` of your route component. If
64
-
you'd like to get it deeper in the tree, you can use whatever
65
-
conventions your app has for getting props from high down low. One
66
-
option is to provide it on context yourself:
71
+
Access `location` from `this.props.location` of your `Route` component. If you'd like to get it deeper in the tree, you can use whatever conventions your app has for getting props from high down low. One option is to provide it on context yourself:
0 commit comments