历史推送和替换之间的权衡是什么? [英] What is the trade off between history push and replace?
问题描述
我使用历史记录程序包将无效的URL重定向到我的react组件上的404页面。
I use History package to redirect invalid URL to 404 page on my react component.
我使用 .replace
而不是 .push
是因为我不不想让浏览器记录我访问过的任何无效网址。
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 ;)
推荐答案
我认为您有正确的主意。
I think you have the right idea.
从无效网址(或无关网址)重定向时,我个人使用 .replace
登录用户访问 / login URL时进入页面),因此使用浏览器的后退按钮对最终用户而言是正确的。
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.
这篇关于历史推送和替换之间的权衡是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!