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?
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.
Redirecting in react-router-dom v6 is done with the <Navigate> Component with replace props.
You just need to add
import { Redirect } from 'react-router';
In the top of your file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With