[react] The difference between BrowserRouter and HashRouter in react:


insert image description here

1. The underlying principles are different:

BrowserRouter uses H5's history API, 不兼容IE9及以下版不.
HashRouter uses the hash value of the URL.

2. The display form of path is different

In the path of BrowserRouter 没有#, for example: localhost:300@/demo/test
The path of HashRouter 包含#, for example: localhost:3e@/#/demo/test

3. The impact on Lushan state parameters after refresh

(1).BrowserRouter 没有任何影响, because the state is stored in the history object.
(2). HashRouter 刷新后会导致路山state参数的丢失.

4. Remarks: HashRouter can be used for解决一些路径错误相关的问题

Guess you like

Origin blog.csdn.net/weixin_53791978/article/details/132128115