mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 18:17:31 +08:00
fix(vue): switching between tabs and going back resolves to correct route (#25206)
resolves #24303
This commit is contained in:
@ -83,17 +83,25 @@ export const createLocationHistory = () => {
|
||||
*/
|
||||
const clearHistory = (routeInfo?: RouteInfo) => {
|
||||
if (routeInfo) {
|
||||
const { position, tab } = routeInfo;
|
||||
|
||||
/**
|
||||
* If there is no route index in locationHistory
|
||||
* then there will not be any route index in
|
||||
* tabs either.
|
||||
*/
|
||||
const existingRouteIndex = locationHistory.findIndex(r => r.position === routeInfo.position);
|
||||
const existingRouteIndex = locationHistory.findIndex(r => r.position === position);
|
||||
if (existingRouteIndex === -1) return;
|
||||
|
||||
locationHistory.splice(existingRouteIndex);
|
||||
|
||||
const clearTabHistory = (tab: string) => {
|
||||
const existingTabRouteIndex = tabsHistory[tab].findIndex(r => r.position === position);
|
||||
if (existingTabRouteIndex === -1) return;
|
||||
|
||||
tabsHistory[tab].splice(existingTabRouteIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* We also need to search the current tab
|
||||
* to correctly reset the individual tab
|
||||
@ -101,19 +109,31 @@ export const createLocationHistory = () => {
|
||||
* tab stack as that means we will lose
|
||||
* a reference to the root tab route.
|
||||
*/
|
||||
const { tab } = routeInfo;
|
||||
const tabHistory = tabsHistory[tab];
|
||||
if (tab && tabHistory) {
|
||||
const existingTabRouteIndex = tabHistory.findIndex(r => r.position === routeInfo.position);
|
||||
if (existingTabRouteIndex === -1) return;
|
||||
|
||||
tabsHistory[tab].splice(existingTabRouteIndex);
|
||||
clearTabHistory(tab);
|
||||
/**
|
||||
* If we are not clearing items after
|
||||
* a tabs page, it is still possible
|
||||
* that there are future tabs pages to clear.
|
||||
* As a result, we need to search through
|
||||
* all the tab stacks and remove views that appear
|
||||
* after the given routeInfo.
|
||||
*
|
||||
* Example: /non-tabs-page --> /tabs/tab1 --> /non-tabs-page
|
||||
* (via router.go(-1)) --> /tabs/tab2. The /tabs/tab1 history
|
||||
* has been overwritten with /tabs/tab2. As a result,
|
||||
* the /tabs/tab1 route info in the Tab 1 stack should be removed.
|
||||
*/
|
||||
} else {
|
||||
for (const tab in tabsHistory) {
|
||||
clearTabHistory(tab);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Object.keys(tabsHistory).forEach(key => {
|
||||
tabsHistory[key] = [];
|
||||
});
|
||||
for (const tab in tabsHistory) {
|
||||
tabsHistory[tab] = [];
|
||||
}
|
||||
|
||||
locationHistory.length = 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user