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: {} },