Appendix C. Additional React Router 4 use cases
This appendix covers
- Handling third-party libraries such as an analytics module in React Router 4
- Adding routes dynamically at runtime
- Code splitting with webpack and React Router 4
Chapters 10 and 11 show you how to do several things that affect the way the React Router code and the rest of the app work together. This appendix goes over several of those examples with React Router 4.
All the examples in this appendix live in the react-router-4 branch (git checkout react-router-4) of the main example repo, http://mng.bz/S3N0. The code in this branch is also updated so you can see a complete example of the way React Router 4 works with the final version of the code as it exists at the end of chapter 11. This builds off the code changes presented in appendix A and appendix B.
The first update you need to make is to move the analytics code into the onRouteChange HOC. Previously, this was handled in the React Router 3 lifecycle methods. Now you’ll handle it like page tracking and prefetching data are in appendix A. The following listing demonstrates how this is done. This change is from chapter 10, section 10.1.