由于版本问题,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');
}
...
}

参考:https://stackoverflow.com/questions/36467126/reactjs-can-not-read-property-push-of-undefined/43266270

(毕)

React报错 :browserHistory doesn't exist in react-router的更多相关文章

  1. 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 ...

  2. react 报错的堆栈处理

    react报错 Warning: You cannot PUSH the same path using hash history 在Link上使用replace 原文地址https://reactt ...

  3. React报错之Property 'value' does not exist on type EventTarget

    正文从这开始~ 总览 当event参数的类型不正确时,会产生"Property 'value' does not exist on type EventTarget"错误.为了解决 ...

  4. 执行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 ...

  5. react报错 TypeError: Cannot read property 'setState' of undefined

    代码如下: class test extends Component { constructor(props) { super(props); this.state = { liked: false ...

  6. React报错之Cannot find name

    正文从这开始~ .tsx扩展名 为了在React TypeScript中解决Cannot find name报错,我们需要在使用JSX文件时使用.tsx扩展名,在你的tsconfig.json文件中把 ...

  7. React报错之Cannot find namespace context

    正文从这开始~ 总览 在React中,为了解决"Cannot find namespace context"错误,在你使用JSX的文件中使用.tsx扩展名,在你的tsconfig. ...

  8. React报错之Expected `onClick` listener to be a function

    正文从这开始~ 总览 当我们为元素的onClick属性传递一个值,但是该值却不是函数时,会产生"Expected onClick listener to be a function" ...

  9. react报错this.setState is not a function

    当报错这个的时候就要看函数是否在行内绑定this,或者在constructor中绑定this. 我这里犯的错误的是虽然我在constructor中绑定了this,但是语法写的不正确. 错误示范: co ...

随机推荐

  1. JMETER断言:终极指南

    你想要: 检查服务器响应是否包含特定字符串, 或验证服务器返回了HTTP 200 OK, 或者检查json字段的值(使用类似JsonPath$.store..price). 断言是要走的路. 问题是: ...

  2. React方法论

    按照目前学习进度不定更新 react渲染的效率,看起来是全体的渲染,其实react在虚拟dom上的处理简直完美.它会过滤掉那些原来就有的东西,不去全体地重复渲染一遍. 即将进入实战,React至今的个 ...

  3. springcloud中常用的注解@

    @SpringBootApplication是springboot启动类,包括三个注解,他们的作用分别是: @Configuration:表示将该类作用springboot配置文件类 @EnableA ...

  4. LeetCode 101 Symmetric Tree 判断一颗二叉树是否是镜像二叉树

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For ex ...

  5. JavaScript 给表格排序

    (function(){ var mTable=document.getElementById('table'); var sort=function(el,index,desc){ var mTbo ...

  6. Gym 101047M Removing coins in Kem Kadrãn

    给定一个序列,只能拿走D,隔壁的会翻转,问能否全部拿走. 注意到如果能拿走的话,拿D的顺序是没关系的.模拟即可 #include <cstdio> #include <cstdlib ...

  7. 【JavaEE】tomcat部署项目的几种方式 .

    一.静态部署1.直接将web项目文件件拷贝到webapps 目录中     Tomcat的Webapps目录是Tomcat默认的应用目录,当服务器启动时,会加载所有这个目录下的应用.所以可以将JSP程 ...

  8. 1.- Netty设计理念-异步和事件驱动

    0. 关键点 a). 非阻塞网络调用,异步方法立即返回 b). 选择器(Selector)使得单一线程就可监控很多连接上的事件. <dependency> <groupId>i ...

  9. Oracle数据库SQL语句操作大全汇总

    数据库各个表空间增长情况的检查: SQL >SELECT A.TABLESPACE_NAME,( 1-(A.TOTAL)/B.TOTAL)* 100 USED_PERCENT FROM (SEL ...

  10. ACdream 1431——Sum vs Product——————【dfs+剪枝】

    Sum vs Product Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) S ...