- 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.
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- 計(jì)算機(jī)網(wǎng)絡(luò)
- OpenDaylight Cookbook
- Node.js Design Patterns
- Java完全自學(xué)教程
- Vue.js快跑:構(gòu)建觸手可及的高性能Web應(yīng)用
- 前端架構(gòu):從入門到微前端
- Julia for Data Science
- Node學(xué)習(xí)指南(第2版)
- C++編程兵書
- Bootstrap for Rails
- 深入分析GCC
- Applied Deep Learning with Python
- Wearable:Tech Projects with the Raspberry Pi Zero
- Android應(yīng)用開發(fā)攻略