Backend routing
In the Rendering to strings section, you implemented a single request handler in the server that responded to requests for the root URL (/
). Your application is going to need to handle more than a single route. You learned how to use the react-router
package for routing in Chapter 9, Handling Navigation with Routes, but now, you're going to see how to use the same package in Node.js.
First, let's take a look at the main App
component:
import { Routes, Route, Link, Outlet } from "react-router-dom"; import FirstHeader from "./first/FirstHeader"; import FirstContent from "./first/FirstContent"; import SecondHeader from "./second/SecondHeader"; import SecondContent from "./second/SecondContent"; function Layout() { return ( <section> <Outlet /> </section> ); } export...