-
Book Overview & Buying
-
Table Of Contents
React and React Native - Sixth Edition
By :
In this section, you'll learn how to create links. You might be tempted to use the standard <a> elements to link to pages controlled by react-router. The problem with this approach is that these links, in simple terms, will try to locate the page on the backend by sending a GET request. This isn't what we want because the route configuration is already in the app, and we can handle routes locally.
First, you'll see an example that illustrates how <Link> components behave somewhat like <a> elements, except that they work locally. Then, you'll see how to build links that use URL parameters and query parameters.
The idea of links in React apps is that they point to routes that point to components, which render new content. The Link component also takes care of the browser history API and looks up route-component mappings. Here's an application component that renders two links:
function Layout() {
return (
...