1.頁面有有個按鈕,點擊這個按鈕跳轉(zhuǎn)頁面官方文檔說:使用withRouter解決=====================importReactfrom'react'importPropTypesfrom'prop-types'import{withRouter}from'react-router'classShowTheLocationextendsReact.Component{staticpropTypes={match:PropTypes.object.isRequired,location:PropTypes.object.isRequired,history:PropTypes.object.isRequired}render(){const{match,location,history}=this.propsreturn(Youarenowat{location.pathname})}}constShowTheLocationWithRouter=withRouter(ShowTheLocation)=====================在實際應(yīng)用的時候這段代碼怎么用呢?withRouter是一個高階組件?返回一個ShowTheLocationWithRouter函數(shù)?那這個函數(shù)怎么用到跳轉(zhuǎn)呢?const{match,location,history}=this.props//這行是什么意思呢?使用history.push('/xxx')這樣嗎現(xiàn)在有一個button組件怎么在這個組件上添加事件進行路由跳轉(zhuǎn)呢
如何在react-router4.2中使用js 路由跳轉(zhuǎn)?
收到一只叮咚
2019-05-15 10:42:52