mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 18:17:31 +08:00
fix(vue): routing history is correctly replaced when overwriting browser history (#24670)
resolves #23873
This commit is contained in:
@ -85,11 +85,25 @@ export const createLocationHistory = () => {
|
||||
locationHistory.push(routeInfo);
|
||||
}
|
||||
|
||||
const clearHistory = () => {
|
||||
locationHistory.length = 0;
|
||||
/**
|
||||
* Wipes the location history arrays.
|
||||
* You can optionally provide a routeInfo
|
||||
* object which will wipe that entry
|
||||
* and every entry that appears after it.
|
||||
*/
|
||||
const clearHistory = (routeInfo?: RouteInfo) => {
|
||||
Object.keys(tabsHistory).forEach(key => {
|
||||
tabsHistory[key] = [];
|
||||
});
|
||||
|
||||
if (routeInfo) {
|
||||
const existingRouteIndex = locationHistory.findIndex(r => r.position === routeInfo.position);
|
||||
if (existingRouteIndex === -1) return;
|
||||
|
||||
locationHistory.splice(existingRouteIndex);
|
||||
} else {
|
||||
locationHistory.length = 0;
|
||||
}
|
||||
}
|
||||
const getTabsHistory = (tab: string): RouteInfo[] => {
|
||||
let history;
|
||||
@ -105,17 +119,6 @@ export const createLocationHistory = () => {
|
||||
|
||||
const size = () => locationHistory.length;
|
||||
|
||||
const updateByHistoryPosition = (routeInfo: RouteInfo, updateEntries: boolean) => {
|
||||
const existingRouteIndex = locationHistory.findIndex(r => r.position === routeInfo.position);
|
||||
if (existingRouteIndex === -1) return;
|
||||
|
||||
locationHistory[existingRouteIndex].pathname = routeInfo.pathname;
|
||||
|
||||
if (updateEntries) {
|
||||
locationHistory[existingRouteIndex].pushedByRoute = routeInfo.pushedByRoute;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns the location history item
|
||||
* given the state of browser's history API.
|
||||
@ -205,7 +208,6 @@ export const createLocationHistory = () => {
|
||||
|
||||
return {
|
||||
current,
|
||||
updateByHistoryPosition,
|
||||
size,
|
||||
last,
|
||||
previous,
|
||||
@ -214,6 +216,7 @@ export const createLocationHistory = () => {
|
||||
update,
|
||||
getFirstRouteInfoForTab,
|
||||
getCurrentRouteInfoForTab,
|
||||
findLastLocation
|
||||
findLastLocation,
|
||||
clearHistory
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user