Chapter 13. React routing
This chapter covers
- Implementing a router from scratch
- Working with React Router
- Routing with Backbone
In the past, in many single-page applications, the URL rarely, if ever, changed as you progressed through the app. There was no reason to go to the server, thanks to browser rendering! Only the content on part of the page changed. This approach had some unfortunate consequences:
- Refreshing your browser took you back to the original form of the page you were reading.
- Clicking the Back button in your browser might take you to a completely different site, because the browser’s history function only recorded a single URL for the site you were on. There were no URL changes reflecting your navigation between content.
- You couldn’t share a precise page on the site with your friends.
- Search engines couldn’t index the site because there were no distinct URLs to index.
Fortunately, today we have browser URL routing. URL routing lets you configure an application to accept request URLs that don’t map to physical files. Instead, you can define URLs that are semantically meaningful to users, that can help with search-engine optimization (SEO), and that can reflect your application’s state. For example, a URL for a page that displays product information might be