September 2018
Beginner
156 pages
3h 28m
English
A <Link> component is used to navigate to an <indexentry content=" component:about"> existing route that is defined using the <Route> component. To navigate to a route, specify the pathname used in the route as a value to the to prop:
import { Link } from 'react-router-dom';class App extends Component { render() { return ( <div class="container"> <nav> <Link to="/">Home</Link> <Link to="/dashboard">Dashboard</Link> </nav> <Route path="/" component={HomeComponent} exact /> <Route path="/dashboard" component={DashboardComponent} /> </div> ); }}
Notice that the to prop's value is the same as the value assigned to the path prop in <Route>. The page now renders two links:
When you click on Home, you will see the text Inside ...
Read now
Unlock full access