Skip to content

Commit

Permalink
Update v5 migration guide for Link changes (#8663)
Browse files Browse the repository at this point in the history
  • Loading branch information
cvbuelow authored Feb 16, 2022
1 parent e5d5b70 commit 7668662
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- chaance
- chasinhues
- christopherchudzicki
- cvbuelow
- edwin177
- elylucas
- hongji00
Expand Down
12 changes: 11 additions & 1 deletion docs/upgrading/v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,17 @@ function App() {
}
```

If you need to replace the current location instead of push a new one onto the history stack, use `navigate(to, { replace: true })`. If you need state, use `navigate(to, { state })`. You can think of the first argument to `navigate` as your `<Link to>` and the other arguments as the `replace` and `state` props.
If you need to replace the current location instead of push a new one onto the history stack, use `navigate(to, { replace: true })`. If you need state, use `navigate(to, { state })`. You can think of the first argument to `navigate` as your `<Link to>` and the other arguments as the `replace` and `state` props. The `Link` component in v6 accepts `state` as a separate prop instead of receiving it as part of the object passed to `to` so you'll need to update your `Link` components if they are using `state`:

```js
import { Link } from "react-router-dom";

// Change this:
<Link to={{ pathname: "/home", state: state }} />

// to this:
<Link to="/home" state={state} />
```

If you prefer to use a declarative API for navigation (ala v5's `Redirect` component), v6 provides a `Navigate` component. Use it like:

Expand Down

0 comments on commit 7668662

Please sign in to comment.