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
Routercomponent. You’ll generally have one of these, and there are a bunch of different types. The basic one isBrowserRouterbut you’ll undoubtedly upgrade toHistoryRouterif 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
Routescomponent. This is analogous to theswitchstatement in our existingAppcomponent. It has a list ofRoutechildren and will...