cluster1
cluster1

Reputation: 5684

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?

Moreover:

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?

Upvotes: 5

Views: 708

Answers (1)

Phi Nguyen
Phi Nguyen

Reputation: 3056

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

Upvotes: 2

Related Questions