I am opening a modal on click of a menu item by redirecting the user to a new route. I am changing the route when the modal opens. I want to redirect to the previous screen whenever the user clicks on close or cancel button. I am using the below code-
onCancel = () => {
props.history.goBack();
}
<Modal open={true}, onClose={onCancel}> </Modal>
My component is a functional component and I can see goBack() in my history object, however, this does not work and user is not able to navigate to previous screen. I am trying to achieve this through redirect. Please suggest me if there is anyway.
React version- 16.8.2
react-router-dom- 4.3.1