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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…