From f697421c1b85ce6c98c2a894a06da6d289f9cc99 Mon Sep 17 00:00:00 2001 From: codytseng Date: Tue, 8 Apr 2025 15:18:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PageManager.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/PageManager.tsx b/src/PageManager.tsx index 481de5d8..40940f3f 100644 --- a/src/PageManager.tsx +++ b/src/PageManager.tsx @@ -109,6 +109,7 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { const onPopState = (e: PopStateEvent) => { let state = e.state as { index: number; url: string } | null + console.log('popstate', state) setSecondaryStack((pre) => { const currentItem = pre[pre.length - 1] as TStackItem | undefined const currentIndex = currentItem?.index @@ -202,7 +203,13 @@ export function PageManager({ maxStackSize = 5 }: { maxStackSize?: number }) { } const popSecondaryPage = () => { - window.history.go(-1) + if (secondaryStack.length === 1) { + // back to home page + window.history.replaceState(null, '', '/') + setSecondaryStack([]) + } else { + window.history.go(-1) + } } const clearSecondaryPages = () => {