Answer the question
In order to leave comments, you need to log in
How to set up a redirect in react-router-dom?
There is a switch
<Switch>
<Route path="/contacts" exact>
<ContactsPage />
</Route>
<Route path="/contacts/add" exact>
<AddContactForm />
</Route>
<Redirect to="/contacts" />
</Switch>
Answer the question
In order to leave comments, you need to log in
You don't need a redirect for this, just set the default route
<Switch>
<Route path="/contacts" exact>
<ContactsPage />
</Route>
<Route path="/contacts/add" exact>
<AddContactForm />
</Route>
<Route path="*" >
<ContactsPage />
</Route>
</Switch>
<Switch>
<Route path="/contacts/add" exact>
<AddContactForm />
</Route>
<Route path="/contacts">
<ContactsPage />
</Route>
</Switch>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question