From 1b7171ad22650a696e8ba8aa348dd2a254b6b8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chyeonggkim=E2=80=9D?= <“hyeonggkim@smilegate.com”> Date: Wed, 12 Nov 2025 12:53:17 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=20=EB=92=A4?= =?UTF-8?q?=EB=A1=9C=EA=B0=80=EA=B8=B0=20=EC=88=98=EC=A0=95=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/error.vue | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/error.vue b/app/error.vue index e2f4873..d9ab11f 100644 --- a/app/error.vue +++ b/app/error.vue @@ -64,6 +64,7 @@ const { tm } = useI18n() const props = withDefaults(defineProps(), { error: () => ({}) }) +const router = useRouter() const nuxtError = useError() const currentError = computed(() => props.error || nuxtError.value) @@ -79,12 +80,22 @@ const localePath = useLocalePath() // const handleError = () => clearError({ redirect: '/' }) const handleError = () => { window.location.href = localePath('/') - // clearError({ redirect: `${localePath('/')}` }) + // clearError({ redirect: `${localePath('/brand')}` }) +} +const handleBack = () => { + // 에러 상태를 클리어하고 이전 페이지로 이동 + // popstate 이벤트가 이미 발생한 경우이므로 추가 동작 불필요 + // 키보드 백스페이스의 경우에만 명시적으로 뒤로가기 실행 + window.location.href = localePath('/') + // navigateTo(`${router.currentRoute.value.path}`) } // 500 에러 발생 시 /error 페이지로 리다이렉트 onMounted(() => { + console.log("🚀 ~ 1111 handleBack ~ router:", router) + console.log("🚀 ~ 2222 router.currentRoute.value.path) ~ router:", router.currentRoute.value.path) + const statusCode = currentError.value?.statusCode console.log("🚀 ~ 2222 currentError==:", currentError.value?.message) console.log("🚀 ~ 222222 statusCode:", statusCode) @@ -100,6 +111,30 @@ onMounted(() => { nextTick(() => { isLoading.value = false }) + + // 백스페이스 키 처리 + const handleKeydown = (e: KeyboardEvent) => { + console.log("🚀 ~ handleKeydown ~ e:", e.key) + if (e.key === 'Backspace' && + !['INPUT', 'TEXTAREA'].includes((e.target as HTMLElement).tagName)) { + e.preventDefault() + handleBack() + } + } + + // 브라우저 뒤로가기 버튼 처리 + const handlePopState = () => { + // clearError() + handleBack() + } + + window.addEventListener('keydown', handleKeydown) + window.addEventListener('popstate', handlePopState) + + onUnmounted(() => { + window.removeEventListener('keydown', handleKeydown) + window.removeEventListener('popstate', handlePopState) + }) }) \ No newline at end of file