Skip to content

Commit 667b30f

Browse files
committed
feat: 히스토리 별 뒤로가기 분기 처리 추가
1 parent 09c8e1b commit 667b30f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/components/mobile-bottom-tab.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ export function MobileBottomTab() {
5454
const pathname = usePathname();
5555
const { theme, toggleTheme } = useTheme();
5656

57+
// Track previous pathname for back navigation
58+
const prevPathname = useRef<string | null>(null);
59+
useEffect(() => {
60+
return () => { prevPathname.current = pathname; };
61+
}, [pathname]);
62+
5763
// --- Scroll hide logic ---
5864
const enableHideByScroll = useMemo(() => {
5965
return hideOnRoutes.some((m) => matchRoute(pathname, m));
@@ -209,9 +215,17 @@ export function MobileBottomTab() {
209215
navigateTo(tabs[clampedIndex].href);
210216
}
211217
} else if (touchedTabIndex.current !== null) {
212-
// Tap on a tab — navigate (even if same tab, pathname might differ)
213218
const i = touchedTabIndex.current;
214-
if (tabs[i].href !== pathname) {
219+
const isPostPage = pathname.startsWith("/post");
220+
221+
if (isPostPage && tabs[i].href === "/") {
222+
// On post page, Undo2 button: go back if previous page was internal, else home
223+
if (prevPathname.current && !prevPathname.current.startsWith("/post")) {
224+
document.dispatchEvent(new Event("transition-back"));
225+
} else {
226+
navigateTo("/");
227+
}
228+
} else if (tabs[i].href !== pathname) {
215229
navigateTo(tabs[i].href);
216230
}
217231
}

src/components/page-transition.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ export function PageTransition({ children }: { children: ReactNode }) {
125125
router.back();
126126
}, [router, animateOut]);
127127

128+
// Listen for custom "transition-back" event from outside PageTransition
129+
useEffect(() => {
130+
const handler = () => { transitionBack(); };
131+
document.addEventListener("transition-back", handler);
132+
return () => document.removeEventListener("transition-back", handler);
133+
}, [transitionBack]);
134+
128135
return (
129136
<TransitionRouterContext
130137
value={{ push: transitionPush, back: transitionBack }}

0 commit comments

Comments
 (0)