fix(reat): fix tab currentHref when changing tabs, closes #21834 (#21835)

This commit is contained in:
Ely Lucas
2020-07-29 10:48:45 -06:00
committed by GitHub
parent 2eaab23f38
commit 74468ab797
2 changed files with 21 additions and 1 deletions

View File

@@ -241,6 +241,25 @@ describe('Navigation Tests', () => {
cy.ionPageVisible('settings-page')
})
it('/routing/ > Details 1 > Details 2 > Details 3 > Back > Settings Tab > Home Tab > Should be at details 2 page', () => {
// fixes an issue where route history was being lost after starting to go back, switching tabs
// and switching back to the same tab again
// for bug https://github.com/ionic-team/ionic-framework/issues/21834
cy.visit(`http://localhost:${port}/routing`)
cy.ionPageVisible('home-page')
cy.ionNav('ion-item', 'Details 1')
cy.ionPageVisible('home-details-page-1')
cy.ionNav('ion-button', 'Go to Details 2')
cy.ionPageVisible('home-details-page-2')
cy.ionNav('ion-button', 'Go to Details 3')
cy.ionPageVisible('home-details-page-3')
cy.ionBackClick('home-details-page-3')
cy.ionPageVisible('home-details-page-2')
cy.ionTabClick('Settings')
cy.ionPageVisible('settings-page')
cy.ionTabClick('Home')
cy.ionPageVisible('home-details-page-2')
})
/*
Tests to add:
Test that lifecycle events fire

View File

@@ -110,6 +110,7 @@ class IonTabBarUnwrapped extends React.PureComponent<InternalProps, IonTabBarSta
}
}
});
const { activeTab: prevActiveTab } = state;
if (activeTab && prevActiveTab) {
const prevHref = state.tabs[prevActiveTab].currentHref;
@@ -121,7 +122,7 @@ class IonTabBarUnwrapped extends React.PureComponent<InternalProps, IonTabBarSta
originalRouteOptions: tabs[activeTab].originalRouteOptions,
currentRouteOptions: props.routeInfo?.routeOptions
};
if (props.routeInfo.routeAction === 'pop') {
if (props.routeInfo.routeAction === 'pop' && (activeTab !== prevActiveTab)) {
// If navigating back and the tabs change, set the prev tab back to its original href
tabs[prevActiveTab] = {
originalHref: tabs[prevActiveTab].originalHref,