Skip to content

Commit 7434af7

Browse files
committed
Some additional upgrade cleanups 🚿
1 parent 07f2510 commit 7434af7

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

upgrade-guides/v2.0.0.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ We have done our best to provide backwards compatibility with deprecated APIs. I
2424

2525
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!
2626

27-
## Router `history` prop
27+
## Using `history` with `Router`
2828

29-
### Default Hash History
29+
### History singletons provided
3030

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.
3238

3339
```js
3440
// v1.x
@@ -37,33 +43,32 @@ The deprecation warnings should also lead you to the relevant part of this docum
3743
// v2.0.0
3844
// hash history
3945
import { hashHistory } from 'react-router'
40-
<Router history={hashHistory}/>
46+
<Router history={hashHistory} />
4147
```
4248

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`.
4452

4553
```js
4654
// v1.x
4755
import createBrowserHistory from 'history/lib/createBrowserHistory'
48-
<Router history={createBrowserHistory()}/>
56+
<Router history={createBrowserHistory()} />
4957

5058
// v2.0.0
5159
import { browserHistory } from 'react-router'
52-
<Router history={browserHistory}/>
60+
<Router history={browserHistory} />
5361
```
5462

55-
## Changes to provided context and Mixins
63+
## Changes to context and Mixins
5664

57-
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.
5866

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.
6068

6169
### Accessing location
6270

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:
6772

6873
```js
6974
// v2.0.x

0 commit comments

Comments
 (0)