If I\'m always redirecting to in-app routes, what\'s the difference between the Redirect
component in react-router-dom (v4), and this.props.history.push()
I am someone who is sternly against rendering redirects as it is kind of counterintuitive that you have to render a component in order to change the page however it does provide some clear benefits
so the issue with this.props.history.push()
is mostly when you are dealing with child components that are triggering redirects
Component A # the one Rendered by the Route
Component B
Component C # the one triggering the redirect
in the example above, unless you are diligent with passing down the route props from Component A
down to Component C
, then you wouldn't be able to use history.push()
in Component C
Rendering Redirect
was supposed to be the answer to that scenario that was provided by the maintainer of react-router but some people just dont like the idea at all(me included).
Functioanally speaking, there doesnt seem to be major differences in functionality between Redirect
and history.push
as Redirect uses it under the hood. The major reason to use Redirect over history.push is that Redirect is future proofed from possible changes on how history would work or if they decide to handle context differently at a later date.