Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between hashHistory and browserHistory in react router?

I have googled quite some bit, but I didn't find a clear answer to the following question: What is the difference between hashHistory and browserHistory in react-router?

like image 227
Ben Bieler Avatar asked Mar 29 '16 16:03

Ben Bieler


Video Answer


3 Answers

The basic difference is that the hashHistory uses URLs like: http://myurl.com/#page/another_page/another_page

With BrowserHistory you get normal urls (no hash): http://myurl.com/page/another_page/another_page

like image 170
smcdrc Avatar answered Oct 13 '22 12:10

smcdrc


First difference:

They are using different WEB APIs. <HashRouter> uses and reads the hash from URL, <BrowserRouter> uses window.history WEB API.

Second difference:

<HashRouter> is used for static one-page website. Ideal for browser based projects. <BrowserRouter> is used for dynamic website. Should be used when you have a server that will handle dynamic requests (knows how to respond to any possible URL).

like image 8
Bojan Golubovic Avatar answered Oct 13 '22 12:10

Bojan Golubovic


I don't think the question was asking for differences in the format, but rather technical. Hence sharing this answer here with a technical difference: https://stackoverflow.com/a/42157741/2445694

Basically the browser don't send the url after the #

So suppose that a website restricted areas for members and admins. A user navigates to /member, and is prompted for logging in. However the server won't know if the user was trying to access /admin or /member before getting on the log in page, so after logging in the server don't know where to redirect.

like image 4
luanped Avatar answered Oct 13 '22 12:10

luanped