0

I am working with React Router and I want to change url after data has been fetched. I was trying many solutions but any of them seem to work. One of the solutions was this.props.history.push('/some/path') but wherever I put it I get the error:

Cannot read property 'push' of undefined

I use import {BrowserRouter as Router} from 'react-router-dom'

1 Answer 1

1

You might not be getting history in your props:

You need to make use of the withRouter

import { withRouter} from 'react-router-dom';

then you need to export your component with withRouter:

export default withRouter(componentName)

then you can use the line:

this.props.history.push('/some/path')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.