Skip to content

Commit 53d1166

Browse files
committed
fix: 회원가입 뒤로가기 오류 수정2
1 parent 0199618 commit 53d1166

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/app/signup/page.tsx

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,38 @@ const SignupPage: React.FC = () => {
111111
e.returnValue = '';
112112
};
113113

114-
let hasShownAlert = false; // 추가
115-
116-
const pushStateAndShowAlert = () => {
117-
// alert('페이지를 나가시면 진행 중인 작업이 저장되지 않습니다.');
118-
// window.history.pushState(null, '', window.location.href);
119-
if (!hasShownAlert) {
120-
alert('페이지를 나가시면 진행 중인 작업이 저장되지 않습니다.');
121-
hasShownAlert = true;
122-
} else {
123-
window.removeEventListener('popstate', pushStateAndShowAlert);
124-
window.history.back();
125-
}
126-
};
114+
// const pushStateAndShowAlert = () => {
115+
// alert('페이지를 나가시면 진행 중인 작업이 저장되지 않습니다.');
116+
// window.history.pushState(null, '', window.location.href);
117+
// };
127118

128119
window.addEventListener('beforeunload', handleBeforeUnload);
129120
window.history.pushState(null, '', window.location.href);
130-
window.addEventListener('popstate', pushStateAndShowAlert);
121+
// window.addEventListener('popstate', pushStateAndShowAlert);
131122

132123
return () => {
133124
window.removeEventListener('beforeunload', handleBeforeUnload);
134-
window.removeEventListener('popstate', pushStateAndShowAlert);
125+
// window.removeEventListener('popstate', pushStateAndShowAlert);
135126
};
136127
}, []);
137128

129+
useEffect(() => {
130+
const handlePopState = (event: PopStateEvent) => {
131+
const step = event.state?.step || 1;
132+
if (step < currentStep) {
133+
setCurrentStep(step);
134+
} else {
135+
router.back();
136+
}
137+
};
138+
139+
window.addEventListener('popstate', handlePopState);
140+
141+
return () => {
142+
window.removeEventListener('popstate', handlePopState);
143+
};
144+
}, [currentStep, router]);
145+
138146
return (
139147
<>
140148
<Suspense fallback={<div></div>}>

0 commit comments

Comments
 (0)