mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(vue): tabs no longer get unmounted when navigating back to a tabs context (#24337)
resolves #24332 Co-authored-by: Liam DeBeasi <liamdebeasi@icloud.com>
This commit is contained in:
@ -15,6 +15,10 @@ import { IonRouterOutlet as IonRouterOutletCmp } from '@ionic/core/components/io
|
|||||||
import { matchedRouteKey, routeLocationKey, useRoute } from 'vue-router';
|
import { matchedRouteKey, routeLocationKey, useRoute } from 'vue-router';
|
||||||
import { fireLifecycle, generateId, getConfig, defineCustomElement } from '../utils';
|
import { fireLifecycle, generateId, getConfig, defineCustomElement } from '../utils';
|
||||||
|
|
||||||
|
const isViewVisible = (enteringEl: HTMLElement) => {
|
||||||
|
return !enteringEl.classList.contains('ion-page-hidden') && !enteringEl.classList.contains('ion-page-invisible');
|
||||||
|
}
|
||||||
|
|
||||||
let viewDepthKey: InjectionKey<0> = Symbol(0);
|
let viewDepthKey: InjectionKey<0> = Symbol(0);
|
||||||
export const IonRouterOutlet = /*@__PURE__*/ defineComponent({
|
export const IonRouterOutlet = /*@__PURE__*/ defineComponent({
|
||||||
name: 'IonRouterOutlet',
|
name: 'IonRouterOutlet',
|
||||||
@ -218,13 +222,35 @@ export const IonRouterOutlet = /*@__PURE__*/ defineComponent({
|
|||||||
|
|
||||||
See https://ionicframework.com/docs/vue/navigation#ionpage for more information.`);
|
See https://ionicframework.com/docs/vue/navigation#ionpage for more information.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enteringViewItem === leavingViewItem) return;
|
if (enteringViewItem === leavingViewItem) return;
|
||||||
|
|
||||||
if (!leavingViewItem && prevRouteLastPathname) {
|
if (!leavingViewItem && prevRouteLastPathname) {
|
||||||
leavingViewItem = viewStacks.findViewItemByPathname(prevRouteLastPathname, id);
|
leavingViewItem = viewStacks.findViewItemByPathname(prevRouteLastPathname, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the entering view is already
|
||||||
|
* visible, then no transition is needed.
|
||||||
|
* This is most common when navigating
|
||||||
|
* from a tabs page to a non-tabs page
|
||||||
|
* and then back to the tabs page.
|
||||||
|
* Even when the tabs context navigated away,
|
||||||
|
* the inner tabs page was still active.
|
||||||
|
* This also avoids an issue where
|
||||||
|
* the previous tabs page is incorrectly
|
||||||
|
* unmounted since it would automatically
|
||||||
|
* unmount the previous view.
|
||||||
|
*
|
||||||
|
* This should also only apply to entering and
|
||||||
|
* leaving items in the same router outlet (i.e.
|
||||||
|
* Tab1 and Tab2), otherwise this will
|
||||||
|
* return early for swipe to go back when
|
||||||
|
* going from a non-tabs page to a tabs page.
|
||||||
|
*/
|
||||||
|
if (isViewVisible(enteringEl) && leavingViewItem !== undefined && !isViewVisible(leavingViewItem.ionPageElement)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fireLifecycle(enteringViewItem.vueComponent, enteringViewItem.vueComponentRef, LIFECYCLE_WILL_ENTER);
|
fireLifecycle(enteringViewItem.vueComponent, enteringViewItem.vueComponentRef, LIFECYCLE_WILL_ENTER);
|
||||||
|
|
||||||
if (leavingViewItem && enteringViewItem !== leavingViewItem) {
|
if (leavingViewItem && enteringViewItem !== leavingViewItem) {
|
||||||
|
@ -290,7 +290,7 @@ describe('Tabs', () => {
|
|||||||
cy.url().should('include', '/tabs/tab1/child-one?key=value');
|
cy.url().should('include', '/tabs/tab1/child-one?key=value');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Verifies fix for https://github.com/ionic-team/ionic-framework/issues/23699
|
// Verifies fix for https://github.com/ionic-team/ionic-framework/issues/24353
|
||||||
it('should handle clicking tab multiple times without query string', () => {
|
it('should handle clicking tab multiple times without query string', () => {
|
||||||
cy.visit('http://localhost:8080/tabs/tab1');
|
cy.visit('http://localhost:8080/tabs/tab1');
|
||||||
|
|
||||||
@ -312,6 +312,33 @@ describe('Tabs', () => {
|
|||||||
cy.ionPageVisible('tab2');
|
cy.ionPageVisible('tab2');
|
||||||
cy.ionPageHidden('tab1');
|
cy.ionPageHidden('tab1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Verifies fix for https://github.com/ionic-team/ionic-framework/issues/24332
|
||||||
|
it('should not unmount tab 1 when leaving tabs context', () => {
|
||||||
|
cy.visit('http://localhost:8080/tabs');
|
||||||
|
cy.ionPageVisible('tab1');
|
||||||
|
|
||||||
|
// Dynamically add tab 4 because tab 3 redirects to tab 1
|
||||||
|
cy.get('#add-tab').click();
|
||||||
|
|
||||||
|
cy.get('ion-tab-button#tab-button-tab4').click();
|
||||||
|
cy.ionPageHidden('tab1');
|
||||||
|
cy.ionPageVisible('tab4');
|
||||||
|
|
||||||
|
cy.get('ion-tab-button#tab-button-tab2').click();
|
||||||
|
cy.ionPageHidden('tab4');
|
||||||
|
cy.ionPageVisible('tab2');
|
||||||
|
|
||||||
|
cy.get('[data-pageid="tab2"] #routing').click();
|
||||||
|
cy.ionPageVisible('routing');
|
||||||
|
cy.ionPageHidden('tabs');
|
||||||
|
|
||||||
|
cy.ionBackClick('routing');
|
||||||
|
cy.ionPageDoesNotExist('routing');
|
||||||
|
cy.ionPageVisible('tabs');
|
||||||
|
cy.ionPageVisible('tab2');
|
||||||
|
cy.ionPageHidden('tab1');
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Tabs - Swipe to Go Back', () => {
|
describe('Tabs - Swipe to Go Back', () => {
|
||||||
|
Reference in New Issue
Block a user