I have tried some of the window methods in component did mount but it wasn't working.
Asked
Active
Viewed 37 times
0
-
please update the question with more information and code snippet. also are you using react-router-dom? if so then use the history api to change the url. history.push('/'); also note that window methods wont work and cause reload. – Anurag Hazra Jun 26 '20 at 09:17
-
yes i am using react-router-dom. this. is what i was trying in componentdidmount() window.addEventListener('popstate', function (event) { if (event.state) { alert('!!'); window.location.replace("/Error/?message= oops! error occured. Do not hit the back button"); } }, false); – Shreyash Kaushal Jun 26 '20 at 09:26
-
2did you checked out this? https://stackoverflow.com/questions/39342195/intercept-handle-browsers-back-button-in-react-router – Anurag Hazra Jun 26 '20 at 09:28