window.history 与 Router.history 返回

Gam*_*007 5 reactjs

为什么我会永远使用路由器从历史react-router-domwindow.history.back()

有没有办法检测用户是来自我的应用程序中的一个页面还是来自特定的外部网站,并据此重定向他?

Gau*_*wat 6

因为。window.history.back()只会更改url in the url bar并重新加载应用程序和所有资源,但不会rerender the correct UI component在路由器历史记录中react-router-dom设置 url 并correct React component根据路由呈现。

第二部分: 不,你不能检测到从外部网站用户来到你的应用程序从如因以安全原因 更多

在您自己的应用程序中是的。您始终可以通过window.onpopstate event 使用情况检测用户是否从您的应用程序页面之一导航。