javascript - React Router : What's the purpose of Browser History? 浏览器历史记录是强制性的吗?

标签 javascript reactjs react-router

浏览器历史记录只是为了在已经访问过的页面之间切换和返回吗?

但是浏览器已经具备了这些能力。为什么需要另一个模块?

此外:

我尝试过 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/

相关文章:

reactjs - 如何修复 “Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0” 错误

reactjs - 如何防止React Router重新渲染之前渲染的页面?

javascript - Node.js 中不存在的行上的隐形神话意外 token

javascript - 输入内容时,按钮调用的下拉列表中的输入表单关闭

reactjs - 提交时在页面上 react 打印 axios POST 响应

reactjs - React 中的离线模式

javascript - React-Router:无限/动态嵌套

node.js - 将图像 blob 上传到 Cloudinary

javascript - 为什么 page.render 在 PhantomJS 中只从页面顶部获取图像?

javascript - Ext.Ux.Printer 打印图像不起作用