我定义了一个像这样的反应路由路径:
/customer/:cid
当我导航到所需的路径时,从我的传奇中调用哈希历史推送:
yield call(hashHistory.push, `/customer/${cid}`);
我没有在浏览器中看到“客户”字样,并且还显示警告显示网址与路由路径不匹配。当我从/${cid}
使用/customer/${cid}
期望时,路由器工作正常。我错过了什么?
答案 0 :(得分:4)
可以尝试:
window.history.pushState(null, null, `#/customer/${cid}`);
或制作模块hashHistory:
// hashHistory.js
import { createHashHistory } from 'history';
export default createHashHistory({});
并使用它:
import hashHistory from './hashHistory';
// ....
hashHistory.push(`/customer/${cid}`);
答案 1 :(得分:1)
我想,您可以跳过第一个以客户为前缀的正斜杠。 因为你推送到hashHistory的url是相对于app root url的。所以只需跳过第一个正斜杠。希望有所帮助