@@ -3,6 +3,8 @@ id: example-react-router
3
3
title : React Router
4
4
---
5
5
6
+ The example below now supports React Router v6.
7
+
6
8
``` jsx
7
9
// app.js
8
10
import React from ' react'
@@ -58,7 +60,7 @@ import {App, LocationDisplay} from './app'
58
60
test (' full app rendering/navigating' , async () => {
59
61
const history = createMemoryHistory ()
60
62
render (
61
- < Router history= {history}>
63
+ < Router location = { history . location } navigator = {history}>
62
64
< App / >
63
65
< / Router> ,
64
66
)
@@ -77,7 +79,7 @@ test('landing on a bad page', () => {
77
79
const history = createMemoryHistory ()
78
80
history .push (' /some/bad/route' )
79
81
render (
80
- < Router history= {history}>
82
+ < Router location = { history . location } navigator = {history}>
81
83
< App / >
82
84
< / Router> ,
83
85
)
@@ -90,7 +92,7 @@ test('rendering a component that uses useLocation', () => {
90
92
const route = ' /some-route'
91
93
history .push (route)
92
94
render (
93
- < Router history= {history}>
95
+ < Router location = { history . location } navigator = {history}>
94
96
< LocationDisplay / >
95
97
< / Router> ,
96
98
)
@@ -158,3 +160,17 @@ test('rendering a component that uses useLocation', () => {
158
160
expect (screen .getByTestId (' location-display' )).toHaveTextContent (route)
159
161
})
160
162
```
163
+
164
+ ## Testing Library and React Router v5
165
+
166
+ In React Router v5, you need to pass the history object as a whole to the Route component.
167
+
168
+ ``` jsx
169
+ test (' full app rendering/navigating' , () => {
170
+ const history = createMemoryHistory ()
171
+ render (
172
+ < Router history= {history} / >
173
+ < App / >
174
+ < / Router> ,
175
+ )
176
+ ` ` `
0 commit comments