Kris MP Kris MP - 1 year ago 58
React JSX Question

What is the trade off between history push and replace?

I use History package to redirect invalid URL to 404 page on my react component.

I use

instead of
simply because I don't want the browser to record any invalid url I have visited.

Am I missed the point here? And there is any trade off choosing between this two for my purpose?

Can someone explain to me? thanks in advance ;)

Answer Source

I think you got the right idea.

I personnaly use .replace when redirecting from an invalid url (or non relevant, i.e. redirect to "profile" page when a logged user goes to the "/login" url), so using the browser's "back" button works properly for the end user.