React 项目使用 React-router-dom 4.0 以上版本时使用 HashRouter 怎么控制 history
Posted zhourongcode
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了React 项目使用 React-router-dom 4.0 以上版本时使用 HashRouter 怎么控制 history相关的知识,希望对你有一定的参考价值。
不添加 history 时,来回点击 Link 会在控制台报错如下
Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack
解决方案是安装使用 history 模块
import createBrowserHistory from "history/createBrowserHistory";
const customHistory = createBrowserHistory();
<Router history = {customHistory} />
注意引入的 HashRouter 改变成 Router
以上是关于React 项目使用 React-router-dom 4.0 以上版本时使用 HashRouter 怎么控制 history的主要内容,如果未能解决你的问题,请参考以下文章