react中点击报Cannot update during an existing state transition跳转出错

在写react项目的时候遇到一个这样的报错,根据提示信息我试着将写在render方法中的路由跳转写到了事件函数中,就解决了该问题。

index.js:1 Warning: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.
<Button onClick={
    
     this.props.history.push('/mapPage') }>去地图页面</Button>

/**********************************将上述代码改为:********************************************/


render(){
    
    
	return(
		<div>
			<Button onClick={
    
     this.fnToMap) }>去地图页面</Button>
		</div>
	)
}
fnToMap=()=>{
    
    
	this.props.history.push('/mapPage')
}

Guess you like

Origin blog.csdn.net/cautionHua/article/details/115912755
Recommended