chore(): sync with main

This commit is contained in:
Liam DeBeasi
2021-11-11 10:19:05 -05:00
20 changed files with 365 additions and 81 deletions

View File

@ -84,7 +84,7 @@ describe('Location History', () => {
locationHistory.add({ pathname: '/home' });
locationHistory.add({ pathname: '/login' });
expect(locationHistory.canGoBack(1)).toEqual(true);
expect(locationHistory.canGoBack(2)).toEqual(false);
expect(locationHistory.canGoBack(1, 0, 1)).toEqual(true);
expect(locationHistory.canGoBack(2, 0, 1)).toEqual(false);
});
});

View File

@ -133,7 +133,18 @@ export const createLocationHistory = () => {
}
const previous = () => locationHistory[locationHistory.length - 2] || last();
const last = () => locationHistory[locationHistory.length - 1];
const canGoBack = (deep: number = 1) => locationHistory.length > deep;
/**
* With the introduction of router.go support, we no longer remove
* items from locationHistory as they may be needed again in the future.
* As a result, we need to look at the current position in location history
* to see if users can navigate back n pages. Previously we were checking
* the length of locationHistory, but that only worked since we were pruning
* the array.
*/
const canGoBack = (deep: number = 1, initialHistory: number, currentHistory: number) => {
return currentHistory - deep >= initialHistory;
}
const getFirstRouteInfoForTab = (tab: string): RouteInfo | undefined => {
const tabHistory = getTabsHistory(tab);

View File

@ -301,7 +301,7 @@ export const createIonRouter = (opts: IonicVueRouterOptions, router: Router) =>
const getCurrentRouteInfo = () => currentRouteInfo;
const canGoBack = (deep: number = 1) => locationHistory.canGoBack(deep);
const canGoBack = (deep: number = 1) => locationHistory.canGoBack(deep, initialHistoryPosition, currentHistoryPosition);
const navigate = (navigationOptions: ExternalNavigationOptions) => {
const { routerAnimation, routerDirection, routerLink } = navigationOptions;