Designing React Router applications from a test-first perspective
This section is a run-down of all the major pieces of the React Router ecosystem, just in case you’re not familiar with it. It also contains guidance on how to test a system that relies on React Router.
A list of all the React Router pieces
Here’s what you’ll be working with from the React Router library:
- A
Router
component. You’ll generally have one of these, and there are a bunch of different types. The basic one isBrowserRouter
but you’ll undoubtedly upgrade toHistoryRouter
if you need to manipulate history outside of the router, which, since you’re writing tests, you will. In Chapter 12, Test-Driving Redux, you’ll also see how this is necessary if you’re causing page transitions to occur within Redux actions. - A
Routes
component. This is analogous to theswitch
statement in our existingApp
component. It has a list ofRoute
children and will...