浏览器历史记录只是为了在已经访问过的页面之间切换和返回吗?
但是浏览器已经具备了这些能力。为什么需要另一个模块?
此外:
我尝试过 React Router 没有浏览器历史记录。 React Router 继续工作。我可以通过在地址栏中输入相应的 URL 来获取所有单个组件。
如果我在浏览器历史记录的情况下使用 React Router 会产生什么后果?
最佳答案
如果您的服务器配置为这样的 SPA 应用程序:
NODE server
// serve static assets normally
app.use(express.static(__dirname + '/public'))
// handle every other route with index.html, which will contain
// a script tag to your application's JavaScript file(s).
app.get('*', function (request, response){
response.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
没有browserHistory
,当您导航到除/
之外的其他URL 时,例如/posts/1
并刷新页面。服务器只给你主页。使用 browserHistory
,路由器将正确处理那些 URL
。有关详细信息,请阅读 doc
关于javascript - React Router : What's the purpose of Browser History? 浏览器历史记录是强制性的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39306624/