react-router: Why the preference for browserHistory over hashHistory?

后端 未结 3 924
青春惊慌失措
青春惊慌失措 2021-02-02 01:28

I\'m relatively new to React; apologies if this is a really naive question.

What are the technical advantages to browserHistory that make it prefer

3条回答
  •  走了就别回头了
    2021-02-02 02:09

    What are the technical advantages to browserHistory that make it preferable over hashHistory?

    It allows you to have a server side fallback which:

    1. Allows the first page visited to initialize with HTML (rather than having to fetch all the data with Ajax) which gives better performance
    2. Means the site keeps working even when JS fails (this is also better for search engines).

    This comes at the cost of having to write the server side code to build pages in the same way that the client side code does. Without that, using the history API is objectively worse … but the URLs are, very subjectively, nicer so lots of people do it without the server side half anyway.

提交回复
热议问题