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

JavascriptReactjsReact Router

Javascript Problem Overview


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?

Javascript Solutions


Solution 1 - Javascript

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

Solution 2 - Javascript

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

Solution 3 - Javascript

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.

Solution 4 - Javascript

  1. Browser’s history’s location array contains more than just the locations that have been visited within our application. Allowing access to this list would leak information about a user’s browsing history that websites should not be allowed access to.

  2. Browser history creates location objects whose pathname is the URL’s full pathname. However, you can specify a basename for a history, in which case a portion of the full pathname will be effectively ignored.

  3. Browser History in static file server will have one real location on our server to fetch our HTML from while Hash history uses the hash section of the URL to set and read locations.

  4. Hash History is reliant as it store all of the path information in the hash of a URL.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBen BielerView Question on Stackoverflow
Solution 1 - JavascriptsmcdrcView Answer on Stackoverflow
Solution 2 - JavascriptBojan GolubovicView Answer on Stackoverflow
Solution 3 - JavascriptluanpedView Answer on Stackoverflow
Solution 4 - JavascriptMERLIN THOMASView Answer on Stackoverflow