BrowserRouter使用的是H5的history API,不兼容IE9及以下版本
HashRouter使用的是URL的哈希值
BrowserRouter的路径中没有#,例如:location:3000/demo/test
HashRouter的路径包含#,例如:localhost:3000/#/demo/test
(1)BrowserRouter没有任何影响,因为state保存在history对象中
(2)HashRouter刷新后会导致路由state参数的丢失
BrowserRouter
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
ReactDOM.render(
<BrowserRouter>
{/* The rest of your app goes here */}
</BrowserRouter>,
root
);
HashRouter
import * as React from "react";
import * as ReactDOM from "react-dom";
import { HashRouter } from "react-router-dom";
ReactDOM.render(
<HashRouter>
{/* The rest of your app goes here */}
</HashRouter>,
root
);