import {withRouter} from 'react-router-dom';
並切在導出時候用這個方法包裹住
export default connect(function (state, props){ return state; }, { addItem(item){ return { type: ADD_ITEM, item } } })(withRouter(Panel));
上面代碼主要是結合redux,connect和withRouter誰包住誰都是可以的如果不用redux的話
export default (withRouter(Panel));
這個時候this.props下面就會有history對象了 大家可以自己打印一下
我們通常會用其中的兩個方法 .push(會保存歷史記錄) 與 .replace(替換的意思,不會保存歷史記錄)
this.props.history.replace('/');
這樣就可以通過事件來進行路由跳轉了