- React Router Quick Start Guide
- Sagar Ganatra
- 161字
- 2021-07-23 16:41:33
The exact prop
In our previous <Route> example, let's change the '/home' route path to '/', as shown here:
<div className="container">
<Route
path="/"
component={HomeComponent}
/>
<Route
path="/dashboard"
component={DashboardComponent}
/>
</div>
With these routes in place, when the browser's URL is set to /dashboard, you'll notice that the content from both components is displayed as follows:
Inside Home route
Inside Dashboard route
Here, the '/' in '/dashboard' matches both of the <Route> paths, '/' and '/dashboard' ; therefore it renders content from both the components. To match the browser's location.pathname exactly with the <Route> component's path, add the exact prop to the <Route>, as shown here:
..
<Route
path="/"
component={HomeComponent}
exact
/>
..
Similarly, when you try to access the '/dashboard' and '/dashboard/portfolio' paths, you'll notice that in both instances, DashboardComponent is rendered. To prevent '/dashboard/portfolio' from matching the <Route> component with the '/dashboard' path, add the exact prop.
- Learning LibGDX Game Development(Second Edition)
- LaTeX Cookbook
- Angular UI Development with PrimeNG
- 編寫高質量代碼:改善Python程序的91個建議
- Learning Python Design Patterns(Second Edition)
- HDInsight Essentials(Second Edition)
- Hands-On Automation Testing with Java for Beginners
- Mastering Linux Network Administration
- Working with Odoo
- Java實戰(第2版)
- SQL 經典實例
- 案例式C語言程序設計實驗指導
- 寫給程序員的Python教程
- Java EE 7 with GlassFish 4 Application Server
- 從零開始構建深度前饋神經網絡:Python+TensorFlow 2.x