What is the trade off between history push and replace?

浪子不回头ぞ 提交于 2020-05-25 03:25:28

问题


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

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

Have I missed the point here? And is there a trade-off between choosing one or the other for my purpose?

Can someone explain to me? thanks in advance ;)


回答1:


I think you have the right idea.

I personally 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.




回答2:


router.replace acts like router.push, the only difference is that it navigates without pushing a new history entry, as its name suggests - it replaces the current entry.



来源:https://stackoverflow.com/questions/39340108/what-is-the-trade-off-between-history-push-and-replace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!