React报错 :browserHistory doesn't exist in react-router
由于版本问题,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 {
...
onSubmit() {
...
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 {
...
onSubmit() {
...
history.push('/GetUser');
}
...
}
(毕)
React报错 :browserHistory doesn't exist in react-router的更多相关文章
- React报错:Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix,
今天在开发时报了以下错误,记录一下 我们不能在组件销毁后设置state,防止出现内存泄漏的情况 出现原因直接告诉你了,组件都被销毁了,还设置个锤子的state啊 解决方案: 利用生命周期钩子函数:co ...
- react 报错的堆栈处理
react报错 Warning: You cannot PUSH the same path using hash history 在Link上使用replace 原文地址https://reactt ...
- React报错之Property 'value' does not exist on type EventTarget
正文从这开始~ 总览 当event参数的类型不正确时,会产生"Property 'value' does not exist on type EventTarget"错误.为了解决 ...
- 执行mysqld_safe报错:mysqld does not exist or is not executable
执行mysqld_safe报错: [root@edu data]# /usr/local/mysql5.7/bin/mysqld_safe --user=mysql160427 12:41:28 my ...
- react报错 TypeError: Cannot read property 'setState' of undefined
代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...
- React报错之Cannot find name
正文从这开始~ .tsx扩展名 为了在React TypeScript中解决Cannot find name报错,我们需要在使用JSX文件时使用.tsx扩展名,在你的tsconfig.json文件中把 ...
- React报错之Cannot find namespace context
正文从这开始~ 总览 在React中,为了解决"Cannot find namespace context"错误,在你使用JSX的文件中使用.tsx扩展名,在你的tsconfig. ...
- React报错之Expected `onClick` listener to be a function
正文从这开始~ 总览 当我们为元素的onClick属性传递一个值,但是该值却不是函数时,会产生"Expected onClick listener to be a function" ...
- react报错this.setState is not a function
当报错这个的时候就要看函数是否在行内绑定this,或者在constructor中绑定this. 我这里犯的错误的是虽然我在constructor中绑定了this,但是语法写的不正确. 错误示范: co ...
随机推荐
- javascript 返回上一页面:onclick="javascript:history.back(-1);"
<a href="<a href="javascript :history.back(-1)">返回上一页</a>或<a href=& ...
- C# 枚举类型 enum (一)
1.枚举使用enum关键字来声明,与类同级.枚举可以和类并列也可以 写在类里面,不能写在方法里. 2.枚举是值类型,隐式继承自System.Enum,不能手动修改. System.Enum本身是引用类 ...
- Java面向对象_常用类库api——日期操作类
Data类 类Data表示特定的瞬间,精确到毫秒,也就是程序运行时的当前时间 Data data=new Data();//实例化Data对象,表示当前时间 Calendar类 日历类,使用此类可以将 ...
- [PHP]使用日志进行调试
两种方法: 1.利用自定义函数: //写日志,打印字符串function writelog($str){ $open=fopen("log.txt","a+") ...
- matlab 打不开excel文件
方法论 excel的后缀为.xls, matlab是无法识别的, 需要将其另存为.xlsx文件格式 打开excel, 点击save as, 选中保存的文件格式是.xlsx即可
- mysql存储方式MyISAM 和 InnoDB的区别
MyISAM 和 InnoDB 讲解: InnoDB和MyISAM是许多人在使用MySQL时最常用的两个表类型,这两个表类型各有优劣,视具体应用而定.基本的差别为:MyISAM类型不支持事务处理等高级 ...
- WebApi 实例
REST是设计风格而不是标准. webapi有自己的路由. webservice和wcf的协议都是soap协议,数据的序列化和反序列化都是soap的格式.而webapi是Json的数据传递 webap ...
- Centos 6.5 添加PHP5.6-7.1的源
centOS6.5 安装后 自带的源中php是5.3版本的,对与php一些常用的框架而言 ,已经不能满足需求了: 使用下面的源 就可以更新到php7.1版本了. # rpm -Uvh http://r ...
- JSTL,JQuery,Ajax,Json
JSTL 的定义 1 JSP 标准标签库 (JavaServerPage Standard Tag Library) 2 JSTL 通常会与EL 表达式合作实现JSP页面的编码 JSTL 的 ...
- Day2 HTML基本标签元素
Day2 HTML基本标签元素 HTML: 超文本标记语言(HyperText Mark-up Language ) 1.作用:写网页结构 2.HTML不区分大小写,建议小写 3.文 ...