Data Fetching and Routing Are Tightly Coupled
As mentioned previously, most websites do need to fetch (or send) data and most websites do need more than one page. But it's important to realize that these two concepts are typically closely related.
Whenever a user visits a new page (such as /posts
), it's likely that some data will need to be fetched. In the case of a /posts
page, the required data is probably a list of blog posts that is retrieved from a backend server. The rendered React component (such as Posts
) must therefore send an HTTP request to the backend server, wait for the response, handle the response (as well as potential errors) and, ultimately, display the fetched data.
Of course, not all pages need to fetch data. Landing pages, "About Us" pages, or "Terms & Use" pages probably don't need to fetch data when a user visits them. Instead, data on those pages is likely to be static. It might even be included in the source code...