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 ...
随机推荐
- NppFTP小插件的使用
大家在Linux系统中配置运行环境时,一定会遇到相关配置文件的修改,虽说在Linux系统中可以使用vi,vim的命令进行文本编辑,但是操作起来还是没有在Windows系统中用的爽,特别是操作大文本量的 ...
- CentOS 安装最新的 RabbitMQ 3.7.8
RabbitMQ依赖Erlang,Erlang又依赖很多包,安装非常麻烦,可以如下操作: RabbitMQ在github上有提供新的erlang包(https://github.com/rabbitm ...
- maven POM总结
可继承的字段 version property 其他占坑: parent import scope Dependency_Management中的scope是可以被继承的,http://maven ...
- GHOST来进行备份和还原及菜单介绍
这篇文章主要说的是如何手工操作GHOST来进行备份和还原. GHOST的菜单及功能: 在主菜单中,有以下几项: l Local:本地操作,对本地计算机上的硬盘进行操作. l Peer to peer: ...
- LeetCode 179 Largest Number 把数组排成最大的数
Given a list of non negative integers, arrange them such that they form the largest number.For examp ...
- Hadoop TaskScheduler源码分析
TaskScheduler是MapReduce中的任务调度器.在MapReduce中,JobTracker接收JobClient提交的Job,将它们按InputFormat的划分以及其他相关配置,生成 ...
- 【Unity3D】Tags和Layers
Tags和Layers分别表示是Unity引擎里面的标签和层,他们都是用来对GameObject进行标识的属性,Tags常用于单个GameObject,Layers常用于一组的GameObject.添 ...
- JavaFX常用汇总
1. 描述备注 1.1 参考教程 博客 易百教程 JavaFX中国 1.5 安装 a). 在线安装e(fx)clipse插件 b). 下载安装SceneBuilder c). eclipse重启以后, ...
- java程序中路径问题
JAVA中获取路径: 1.在web中取得路径: 以工程名为TEST为例: (1)得到包含工程名的当前页面全路径:request.getRequestURI() 结果:/TEST/test.jsp ...
- idea代码生成功能 live template
一 界面 二 添加 三 编写模板 模板可以通过看其他的模板学习相应语法,难不倒程序员的 四 选择适应范围 五 本人常用的模板 log private static final Logger log = ...