뒤로가기 버튼
This commit is contained in:
parent
3e873b7861
commit
b24c6d85e4
@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<!-- 뒤로가기 -->
|
||||
<button
|
||||
v-if="canGoBack"
|
||||
@click="goBack"
|
||||
:disabled="!canGoBack"
|
||||
:class="{ 'shifted': showButton }"
|
||||
@ -26,7 +27,7 @@ const showButton = ref(false);
|
||||
const canGoBack = ref(false);
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const loginPage = "/login"; // 로그인 페이지 경로
|
||||
const loginPagePath = "/login"; // 로그인 페이지 기본 경로
|
||||
|
||||
// 스크롤 이벤트 핸들러
|
||||
const handleScroll = () => {
|
||||
@ -50,7 +51,21 @@ const updateCanGoBack = () => {
|
||||
const historyBack = router.options.history.state.back;
|
||||
const previousPage = document.referrer;
|
||||
|
||||
canGoBack.value = !!historyBack && historyBack !== loginPage && !previousPage.includes(loginPage);
|
||||
// URL에서 경로만 추출하는 함수
|
||||
const getPath = (url) => {
|
||||
try {
|
||||
return new URL(url, window.location.origin).pathname; // 쿼리 제거
|
||||
} catch {
|
||||
return ""; // 잘못된 URL 처리
|
||||
}
|
||||
};
|
||||
|
||||
const previousPath = getPath(previousPage);
|
||||
|
||||
// 뒤로 갈 수 있는 조건:
|
||||
canGoBack.value = !!historyBack
|
||||
&& getPath(historyBack) !== loginPagePath
|
||||
&& !previousPath.startsWith(loginPagePath);
|
||||
};
|
||||
|
||||
// 마운트 시 한 번 실행
|
||||
|
||||
Loading…
Reference in New Issue
Block a user