【发布时间】:2020-09-16 07:49:38
【问题描述】:
我有一个具有此配置的历史应用程序:
import { createHashHistory } from 'history';
import { ConnectedRouter } from 'connected-react-router';
const history = createHashHistory({
hashType: 'slash',
});
...
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
但是我所有的路线都被/#附加了
例如:localhost:8080/ 变为:localhost:8080/#/
我已经尝试将我的包更新为this question say,但没有成功。
唯一有效的方法是将createHashHistory 更改为createBrowserHistory,但我不确定它们之间有什么区别,以及为什么createHashHistory 附加/#
【问题讨论】:
-
哈希路由一般是包含
/#/的UI路由。它利用hashchange和window.location.hashAPI 来模拟路由。或者,UI 路由使用historyAPI 更新 URL 并将以前的状态存储在浏览器内存中。
标签: javascript reactjs react-router react-router-dom history.js