I know this question's a little old but I stumbled on it while looking for the answer myself. There's no clean way to "disable" the back button but to enable the user to only close the modal when clicking the browser back button I found this to work.
Simply pass the history to your modal component in props and call the below on the componentWillUnmount
function.
componentWillUnmount() {
this.props.history.goForward();
}
This will seamlessly force the browser to stay on the same page but close the modal (assuming it's a class component).
UPDATE: If using functional components, the above componentWillUnmount function looks like the hook below.
React.useEffect(() => {
return () => {
props.history.goForward();
}
}, []);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…