React Router:浏览器历史记录的目的是什么?浏览器历史记录是强制性的吗?

mic*_*ech 5 javascript reactjs react-router

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

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

而且:

我尝试过没有浏览器历史记录的 React Router。React Router 继续工作。我可以通过在地址栏中输入相应的 URL 来获取所有单个组件。

当我在没有浏览器历史记录的情况下使用 React Router 时会产生什么后果?

Phi*_*yen 2

如果您的服务器配置为这样的 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'))
  })
Run Code Online (Sandbox Code Playgroud)

如果没有,当您导航到除LikebrowserHistory之外的其他 URL并刷新页面时。服务器只为您提供主页。使用,路由器将正确处理这些问题。有关更多信息,请阅读文档//posts/1browserHistoryURL