@@ -3,6 +3,8 @@ id: example-react-router
33title : React Router
44---
55
6+ The example below now supports React Router v6.
7+
68``` jsx
79// app.js
810import React from ' react'
@@ -58,7 +60,7 @@ import {App, LocationDisplay} from './app'
5860test (' full app rendering/navigating' , async () => {
5961 const history = createMemoryHistory ()
6062 render (
61- < Router history= {history}>
63+ < Router location = { history . location } navigator = {history}>
6264 < App / >
6365 < / Router> ,
6466 )
@@ -77,7 +79,7 @@ test('landing on a bad page', () => {
7779 const history = createMemoryHistory ()
7880 history .push (' /some/bad/route' )
7981 render (
80- < Router history= {history}>
82+ < Router location = { history . location } navigator = {history}>
8183 < App / >
8284 < / Router> ,
8385 )
@@ -90,7 +92,7 @@ test('rendering a component that uses useLocation', () => {
9092 const route = ' /some-route'
9193 history .push (route)
9294 render (
93- < Router history= {history}>
95+ < Router location = { history . location } navigator = {history}>
9496 < LocationDisplay / >
9597 < / Router> ,
9698 )
@@ -158,3 +160,17 @@ test('rendering a component that uses useLocation', () => {
158160 expect (screen .getByTestId (' location-display' )).toHaveTextContent (route)
159161})
160162```
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