react-router Redirect vs history.push

tandav picture tandav · Feb 5, 2018 · Viewed 26.4k times · Source

I was reading react-router-redux examples and I confused, what is the difference beetween:

import { Redirect } from 'react-router-dom'

...

<Redirect to='/login' /> 

and

import { push } from 'react-router-redux'

...

push('/login')

Answer

Revansiddh picture Revansiddh · May 25, 2018

Redirect

Rendering a <Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects (HTTP 3xx) do.

whereas History

push function Pushes a new entry onto the history stack