由于版本问题,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. python之垃圾回收机制

    一.前言 Python 是一门高级语言,使用起来类似于自然语言,开发的时候自然十分方便快捷,原因是Python在背后为我们默默做了很多事情,其中一件就是垃圾回收,来解决内存管理,内存泄漏的问题. 内存 ...

  2. 剑指offer刷题记录

    目录 二维数组中的查找 替换空格 从尾到头打印链表 反转链表 重建二叉树 用两个栈实现队列 旋转数组的最小数字 斐波拉切数列 跳台阶 变态跳台阶 矩形覆盖 二进制中1的个数 数值的整次方 链表中倒数第 ...

  3. BestCoder Round #86 1003

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=5806 题意:有多少个区间里的第 k 大的数不小于 m 解法:尺取法,首先我们用dp[i]保存到i的位置有多 ...

  4. 开元java开发工具

    开元java开发工具 http://www.hutool.cn/

  5. 032 Longest Valid Parentheses 最长有效括号

    给一个只包含 '(' 和 ')' 的字符串,找出最长的有效(正确关闭)括号子串的长度.对于 "(()",最长有效括号子串为 "()" ,它的长度是 2.另一个例 ...

  6. 008 String to Integer (atoi) 字符串转换为整数

    详见:https://leetcode.com/problems/string-to-integer-atoi/description/ 实现语言:Java class Solution { publ ...

  7. (转)diff 命令

    每天一个linux命令(36):diff 命令  原文:http://www.cnblogs.com/peida/archive/2012/12/12/2814048.html diff 命令是 li ...

  8. (转)linux命令总结之ip命令

    linux命令总结之ip命令 原文:https://www.cnblogs.com/ginvip/p/6367803.html linux命令总结之ip命令   Linux的ip命令和ifconfig ...

  9. 16.Ubuntu LTS 16.04安装搜狗输入法全过程记录(纯新手)

    这是我第四次打算转到Ubuntu上了,应该不会像以前那样装个系统就拜拜了.打算先把C和Vim重新学起来,数据结构那本书看完写完,第二步是学python和算法导论,暂定如此. 昨天晚上系统装完以后想着要 ...

  10. 操作文件方法简单总结(File,Directory,StreamReader,StreamWrite )(转载)

    本文转自http://www.cnblogs.com/zery/p/3315889.html 对于文件夹,文档的操作一直处于一知半解状态,有时间闲下来了,好好练习了一把,对文档,文件的操作有了一个基本 ...