Skip to content

Commit 4500bfa

Browse files
committed
fix(vue): only remount with delta values
1 parent 51025ae commit 4500bfa

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

packages/vue-router/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export const createIonRouter = (opts: IonicVueRouterOptions, router: Router) =>
258258
}
259259

260260
routeInfo.position = currentHistoryPosition;
261+
routeInfo.delta = delta;
261262
const historySize = locationHistory.size();
262263
const historyDiff = currentHistoryPosition - initialHistoryPosition;
263264

packages/vue-router/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface RouteInfo {
2727
pushedByRoute?: string;
2828
tab?: string;
2929
position?: number;
30+
delta?: number;
3031
}
3132

3233
export interface RouteParams {

packages/vue-router/src/viewStacks.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,34 @@ export const createViewStacks = (router: Router) => {
203203
* developers to step forward over multiple views.
204204
* The intermediary views need to be remounted so that
205205
* swipe to go back works properly.
206+
* We need to account for the delta value here too because
207+
* we do not want to remount an unrelated view.
208+
* Example:
209+
* /home --> /page2 --> router.back() --> /page3
210+
* Going to /page3 would remount /page2 since we do
211+
* not prune /page2 from the stack. However, /page2
212+
* needs to remain in the stack.
213+
* Example:
214+
* /home --> /page2 --> /page3 --> router.go(-2) --> router.go(2)
215+
* We would end up on /page3, but users need to be able to swipe
216+
* to go back to /page2 and /home, so we need both pages mounted
217+
* in the DOM.
206218
*/
207-
const mountIntermediaryViews = (outletId: number, enteringViewItem: ViewItem, leavingViewItem: ViewItem) => {
219+
const mountIntermediaryViews = (outletId: number, enteringViewItem: ViewItem, leavingViewItem: ViewItem, delta: number = 1) => {
208220
const viewStack = viewStacks[outletId];
209221
if (!viewStack) return;
210222

211223
const { enteringIndex: endIndex, leavingIndex: startIndex } = findViewIndex(viewStack, enteringViewItem, leavingViewItem);
224+
let mountDiff = delta - 1;
212225

213226
for (let i = startIndex + 1; i < endIndex; i++) {
214227
viewStack[i].mount = true;
228+
229+
mountDiff -= 1;
230+
231+
if (mountDiff === 0) {
232+
return;
233+
}
215234
}
216235
}
217236

packages/vue/src/components/IonRouterOutlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export const IonRouterOutlet = /*@__PURE__*/ defineComponent({
202202

203203
const handlePageTransition = async () => {
204204
const routeInfo = ionRouter.getCurrentRouteInfo();
205-
const { routerDirection, routerAction, routerAnimation, prevRouteLastPathname } = routeInfo;
205+
const { routerDirection, routerAction, routerAnimation, prevRouteLastPathname, delta } = routeInfo;
206206

207207
const enteringViewItem = viewStacks.findViewItemByRouteInfo(routeInfo, id);
208208
let leavingViewItem = viewStacks.findLeavingViewItemByRouteInfo(routeInfo, id);
@@ -277,7 +277,7 @@ See https://ionicframework.com/docs/vue/navigation#ionpage for more information.
277277
viewStacks.unmountLeavingViews(id, enteringViewItem, leavingViewItem);
278278
}
279279
} else {
280-
viewStacks.mountIntermediaryViews(id, enteringViewItem, leavingViewItem);
280+
viewStacks.mountIntermediaryViews(id, enteringViewItem, leavingViewItem, delta);
281281
}
282282

283283
fireLifecycle(leavingViewItem.vueComponent, leavingViewItem.vueComponentRef, LIFECYCLE_DID_LEAVE);

0 commit comments

Comments
 (0)