React-router configure browserHistory

  browserHistory is the recommended history for applications using React Router, which uses the browser-heavy History API for handling URIs

 

     You can set the devServer in webpack.config.js as follows

 devServer: {
        historyApiFallback:{ index:'src/index.html' }, }

     The actual development uses browserHistory instead of hashHostory (it can be used directly without configuring it on the server):

       browserHistory In fact, HTML5 is used  History API, and the browser provides the corresponding interface to modify the browser's history; hashHistory instead is changed by changing the hash behind the address;

        History API provides pushState() and replaceState() methods to add or replace history records. And hash has no corresponding method, so there is no function to replace the history record. But react-router implements this function through polyfill, the specific implementation is not seen, it seems to use sessionStorage.

Another reason is that the hash part is not sent to the server by the browser, that is to say, whether it is a request  http://domain.com/index.html#foo or  http://domain.com/index.html#bar not, the service only knows that the index.html is requested and does not know the details of the hash part. The History API requires server support, so that the server can obtain the request details.       

Note: (The green text is quoted as a record of learning, not written by me)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325249249&siteId=291194637