Reputation: 1808
I try to use Route to redirect to a component but it returns both components as below.
When it comes to /test/new i just want to display only NewRequest component.
I think the problem is the /:id/ but don't know how to fix it.
Here is my code for Route:
<div>
<Route exact path='/test/' render={(props) => <ViewList />} ></Route>
<Route path='/test/new/' render={(props) => <NewRequest />} ></Route>
<Route path='/test/:id/' render={(props) => <ViewDetail />} ></Route>
</div>
My question is how to fix the Route so it returns only NewRequest component? Thank you.
Upvotes: 0
Views: 32
Reputation: 1316
Wrap your Route
components in Switch
.
import { Route, Switch } from "react-router-dom";
<Switch>
<Route exact path='/test' component={ViewList} />
<Route path="/test/new" component={NewRequest} />
<Route path="/test/:id" component={ViewDetail} />
</Switch>
Upvotes: 2