Using link components
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 will try to locate the page on the backend by sending a GET
request. This isn't what you want because the route configuration is already in the browser.
First, you'll see an example that illustrates how <Link>
elements are just like <a>
elements in most ways. Then, you'll see how to build links that use URL parameters and query parameters.
Basic linking
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:
import * as React from "react"; import { BrowserRouter as Router, ...