Created
January 18, 2021 11:00
-
-
Save sachinKumarGautam/245285add804049a453c859a945b4543 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
/** | |
* trapping next router before-pop-state to manipulate router change | |
* on browser back button quick filter modal should be closed | |
*/ | |
router.beforePopState(() => { | |
if (isOpen) { | |
/** | |
* only applicable if modal is open. | |
*/ | |
onClose(); | |
/** | |
* return false stops next router change but we can not | |
* prevent browser url change. | |
* to prevent go to previous url in browser address bar | |
* we have to use history.forward method. | |
*/ | |
window.history.forward(); | |
return false; | |
} | |
return true; | |
}); | |
return () => { | |
router.beforePopState(() => { | |
return true; | |
}); | |
}; | |
}, [isOpen]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment