由于版本问题,React中history不可用
import { hashHistory } from 'react-router'
首先应该导入react-router-dom包:
import { hashHistory } from 'react-router-dom'
以前的写法:
import React from 'react'; import { hashHistorty } from "react-router"; class Login extends React.Component { ... () { ... hashHistory.push('/GetUser'); } ... }
这种方式会报错:
'react-router' does not contain an export named 'hashHistory'.
可以用 history包 (需要安装 npm install --save history )进行修改:
import React from 'react'; import { createHashHistory } from 'history'; const history = createHashHistory(); class Login extends React.Component { ... () { ... history.push('/GetUser'); } ... }
(毕)
继续阅读与本文标签相同的文章
下一篇 :
JQuery中事件绑定中on绑定的一些小bug
-
上海海思向公开市场推出首款4G通信芯片Balong 711
2026-05-15栏目: 教程
-
想减轻驾驶压力 那千万别错过这三款配备L2智能驾驶系统的SUV
2026-05-15栏目: 教程
-
董明珠造5G公交车:车长18米 可连接5G Wi-Fi
2026-05-15栏目: 教程
-
最有价值品牌TOP100公布 三星611亿美元创新高 排名全球第六
2026-05-15栏目: 教程
-
科技提升“双录”效率,马上金融打造智慧双录服务平台
2026-05-15栏目: 教程
