前言:
- "react-router-dom": "^5.1.2"
在使用Link、NavLink (导航使用)的时候
import { NavLink } from 'react-router-dom';
<NavLink to={item.key}>{item.title}</NavLink>
可能给我们警告:
原因:
- 这个是 react-router 的一个提示,浏览器不会将同样的路径 push 到 stack 里
-
在当前页面点击按钮想重新加载却发现react不刷新当前页面,提示
Warning: You cannot PUSH the same path using hash history
解决:
- 添加上replace
<NavLink to={item.key} replace>{item.title}</NavLink>
-
【已解决】React如何通过路由重新加载当前页面 Warning: You cannot PUSH the same path using hash history
解决方法:只需要新建一个空白页面,先跳转到空白页面,再从空白页面跳转到当前页面即可
index.jsx页面执行:
hashHistory.push({
pathname: '/blank',//空白页面
//pathname: 'app/index',
})
blank页面执行跳转:
componentWillMount(){
hashHistory.push({
pathname: 'app/index',//返回当前页面
})
}