我有一个应用程序的历史配置是这样的。
import { createHashHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
const history = createHashHistory({
hashType: 'slash',
});
...
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
但我所有的路径都被 /#
前 localhost:8080/
变成。localhost:8080/#/
我已经尝试更新我的软件包为 这个问题说 但它没有工作。
唯一有效的是改变 createHashHistory
到 createBrowserHistory
但我不知道它们之间有什么区别,为什么?createHashHistory
是附加的 /#
使用hashHistory,它产生的网址是这样的http:/yourwebsite.net#pagexxx。
使用浏览器历史记录,它产生的网址是http:/yourwebsite.netpagexxx。
该用哪个?在现实世界的产品中,大多使用BrowserHistory。一个经验法则是:"如果你使用的是一个可以处理动态URL的动态服务器,那么你需要使用BrowserRouter组件,但如果你使用的是一个只为静态文件服务的服务器,那么在这种情况下应该使用HashRouter组件。"
在你的代码中,hashType: '斜线'只是默认值。