Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirect in react-router undefined?

Tags:

react-router

This is what my react-router code looks like

render((
<Router history={browserHistory}>
    <Route path={CORP} component={App}>
      <IndexRoute component={Home} />
      <Route path={"outreach"} component={OutReach}/>
      <Route path={"careers/m"} component={Career}/>
      <Route path={"members"} component={Members}/>
      <Redirect from="*" to={"/home"} />
    </Route>
  </Router>
), document.getElementById('app'))

But when I go to my page, I get this error in my console

Uncaught ReferenceError: Redirect is not defined

How do I tell react-router to redirect the user to the /home only when the user's destination does not match any of the route paths mentioned above?

like image 455
John Avatar asked May 10 '17 15:05

John


People also ask

Why is redirect not working in react?

Conclusion # To solve the error "export 'Redirect' (imported as 'Redirect') was not found in 'react-router-dom'", use the Navigate component instead of Redirect , e.g. <Navigate to="/dashboard" replace={true} /> . The Navigate component changes the current location when it's rendered.

What can I use instead of redirect in react?

Redirecting in react-router-dom v6 is done with the <Navigate> Component with replace props.


1 Answers

You just need to add

import { Redirect } from 'react-router';

In the top of your file

like image 179
Vlad Dekhanov Avatar answered Sep 18 '22 14:09

Vlad Dekhanov