Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Router v4 components with similar paths (fixed and dynamic path param) are "overlapping"

My routes are set up like this:

<Route path="/chat/:id" component={Chat} />
<Route path="/chat/new" component={NewChat} />

When I go to chat/new its also displaying {Chat}. Is there any way to exclusively call NewChat when I go to /chat/new?

like image 566
luiquao Avatar asked Dec 22 '17 18:12

luiquao


1 Answers

You would make use of Switch and reorder your Routes, since Switch renders the first matched Route

<Switch>
   <Route path="/chat/new" component={NewChat} />
   <Route path="/chat/:id" component={Chat} />
</Switch>
like image 149
Shubham Khatri Avatar answered Oct 22 '22 23:10

Shubham Khatri