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 ...
随机推荐
- 兼容IE的login表单巧妙写法
利用label来写: HTML: <div class="loginwrap"> <label for="phonenumber" class ...
- 导入别的类中的bean
@Configuration class CommonContext { @Bean public MyBolt myBolt() { return new MyBolt(); } } ... @Co ...
- 记录一个在线压缩和还原压缩js代码的工具
packer – javascript 压缩工具 http://dean.edwards.name/packer/ Javascript Beautifier ---可以恢复某些压缩工具压缩的js代码 ...
- Python 将IP转换为int
import socket import struct if __name__ == '__main__': ip = '127.0.0.1' int_ip = struct.unpack('!I', ...
- OC与JS交互前言
OC与JS交互过程中,可能会需要使用本地image资源及html,css,js文件,这些资源应该如何被加载? 一.WebView加载HTML UIWebView提供了三个方法来加载html资源 1. ...
- ECShop配置文件解析
1. 配置文件位置:/upload/data/config.php 2. 配置解析 <?php // 主机地址 $db_host = ""; // 数据库名称 $db_nam ...
- Quartz 定时器,同时运用多个定时器
效果:每天执行两个定时器,两个定时器不相关联.jar版本Quartz 2.2.3 Java工程结构图 jar 包下载: 链接: https://pan.baidu.com/s/1-7dh620k9P ...
- js清除缓存以及jsp缓存[部分常用]
参考: http://bbs.csdn.net/topics/330028896 浏览器缓存机制 http://www.docin.com/p-591569918.html 浏览器缓存的一些问题的 ...
- redis空间键详解
前言 redis的空间键通知是在2.8.0版本以后加入的,客户端通过发布订阅的方式,订阅某个频道,接收通过某种方式影响redis中数据的事件. 目录: 1.空间键事件分类 2.如何启用redis的空间 ...
- java网络编程—TCP(1)
演示tcp的传输的客户端和服务端的互访. 需求:客户端给服务端发送数据,服务端收到后,给客户端反馈信息. 客户端: 1,建立socket服务.指定要连接主机和端口. 2,获取socket流中的输出流. ...