mizech mizech - 1 year ago 104
Javascript Question

React Router: What's the purpose of Browser History? Is Browser History mandatory?

Is the Browser History just for to change between already visited pages for and back?

But browsers have these ability already. Why is another module needed?


I have tried React Router without Browser History. React Router kept working. I could get all the single components via entering the corresponding URL into the adressbar.

What consequences does it have when I use React Router without Browser History?

Answer Source

if your server config to be a SPA application like this :

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'))

Without browserHistory, when you navigate to other URL except / like /posts/1 and refresh the page. The server only gives you the home page. With browserHistory, the router will handle those URL properly. For more information, read the doc