2025. 5. 13. 09:31
import { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
const PageB = () => {
const history = useHistory();
useEffect(() => {
const unlisten = history.listen((location, action) => {
if (action === 'POP') {
// 뒤로가기 등 pop 이벤트 감지
backToList();
}
});
return () => {
unlisten(); // 컴포넌트 언마운트 시 cleanup
};
}, []);
const backToList = () => {
console.log('뒤로가기 시 호출됨!');
// 필요한 작업 수행
};
return (
<div>
<h1>Page B</h1>
</div>
);
};