From e2bf84aec687aaf5c7943db1d5ae5a88efa4f720 Mon Sep 17 00:00:00 2001 From: lyf <2514544224@qq.com> Date: Sun, 19 Jul 2026 22:50:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B5=8C=E5=85=A5=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E8=AE=B2=E8=A7=A3=E5=88=97=E8=A1=A8=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=AF=BC=E8=A7=88=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/explain/list.vue | 3 ++- tests/unit/ExplainListNavigation.spec.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/pages/explain/list.vue b/src/pages/explain/list.vue index 42f7a99..2fda1be 100644 --- a/src/pages/explain/list.vue +++ b/src/pages/explain/list.vue @@ -122,7 +122,8 @@ const returnToGuideHome = () => { ? previousPage.options.tab[0] : previousPage?.options?.tab const canNavigateBackToGuideHome = ( - previousRoute === 'pages/index/index' + !shouldUseHostNavigation.value + && previousRoute === 'pages/index/index' && (!previousTab || previousTab === 'guide') ) diff --git a/tests/unit/ExplainListNavigation.spec.ts b/tests/unit/ExplainListNavigation.spec.ts index be82d23..3ade3f3 100644 --- a/tests/unit/ExplainListNavigation.spec.ts +++ b/tests/unit/ExplainListNavigation.spec.ts @@ -122,6 +122,25 @@ describe('讲解展厅列表返回', () => { wrapper.unmount() }) + it('微信嵌入态即使前置页是导览首页也不调用宿主返回', async () => { + hostEnvironmentMocks.embeddedInWechatMiniProgram = true + window.location.hash = '#/pages/explain/list?embedded=wechat-mini-program' + window.history.replaceState({}, '', window.location.href) + vi.stubGlobal('getCurrentPages', vi.fn(() => [ + { route: 'pages/index/index', options: { tab: 'guide' } }, + { route: 'pages/explain/list', options: {} } + ])) + const wrapper = mountExplainList() + + await wrapper.get('[data-testid="explain-list-back"]').trigger('click') + + expect(uni.navigateBack).not.toHaveBeenCalled() + expect(uni.reLaunch).toHaveBeenCalledWith(expect.objectContaining({ + url: '/pages/index/index?tab=guide&embedded=wechat-mini-program' + })) + wrapper.unmount() + }) + it('上一页不是首页时使用 reLaunch,避免回到不相关页面', async () => { vi.stubGlobal('getCurrentPages', vi.fn(() => [ { route: 'pages/search/index', options: {} },