2

I'm a beginner in React and stuck with some problem.I have read many blogs but can't able to find why and in which specific case we use these Router type?

Abhijeet
  • 588
  • 1
  • 4
  • 18
  • 1
    What of the documentation for [hashRouter](https://reacttraining.com/react-router/web/api/HashRouter), [browserRouter](https://reacttraining.com/react-router/web/api/BrowserRouter) or [memoryRouter](https://reacttraining.com/react-router/web/api/MemoryRouter) don't you understand? – HMR May 24 '20 at 15:28
  • @HMR No I Can't able to understand from there because they have mentioned in brief. Please help me on this. – Abhijeet May 24 '20 at 15:43
  • 1
    What of the explanation there do you not understand? What information is missing and what you are having trouble with? – poke May 24 '20 at 15:51
  • @poke as mentioned in the docs HashRouter - uses the hash portion of the URL and what is hash portion of URL are they talking about Fragment or anything else ? and similarly for Browser Router - that uses the HTML5 history API and they have also not mentioned why and when we use these routers and for what use-cases they are suitable for ? - Please help me in detail – Abhijeet May 24 '20 at 16:44
  • 1
    The hash router even mentions `window.location.hash` which should give you something you can google to see that it is the fragment of the URL. The docs say that the memory router is _“useful in tests and non-browser environments”_ and the hash router says _“As this technique is only intended to support legacy browsers, we encourage you to configure your server to work with BrowserHistory instead”_. To me that sounds like a clear recommendation for the BrowserRouter by default unless you are in one of the other explained cases. – poke May 25 '20 at 12:15
  • 1
    To understand why static router is needed, please refer to this article --> https://blog.somewhatabstract.com/2020/03/02/static-router-static-assets-serving-a-server-side-rendered-site – Pavindu Jun 04 '20 at 14:22

1 Answers1

0

try looking at - cick

BrowserRouter for the browser and static requests for the server (SSR), and HashRouter must be used for a static site (adds #)

uncodegem
  • 78
  • 1
  • 8
  • As, I have mentioned above this site contain very less information about the router type. Please help me on - why and when we use these routers and for what use-cases they are suitable for ? – Abhijeet May 24 '20 at 19:18
  • so I tell you. BrowserRouter is used for browsers and SSRs, and HashRouter is used only for static sites. – uncodegem May 25 '20 at 04:45
  • Why HashRouter shouldn’t be used for non-static sites? Btw, the link is broken. – Michael Freidgeim Jul 01 '23 at 04:20