React-router-更改获取的数据上的网址

时间:2018-07-08 02:15:17

标签: reactjs react-router

我正在与React Router合作,并且想在获取数据后更改url。我尝试了许多解决方案,但其中任何一个似乎都可以使用。解决方案之一是this.props.history.push('/some/path'),但是无论我放在哪里,都会出现错误:

Cannot read property 'push' of undefined

我使用import {BrowserRouter as Router} from 'react-router-dom'

1 个答案:

答案 0 :(得分:1)

您可能没有在道具中获得历史记录:

您需要使用obj.getClass() == Xyz.class

withRouter

然后您需要使用import { withRouter} from 'react-router-dom'; 导出组件:

withRouter

然后您可以使用以下行:

export default withRouter(componentName)