Skip to content

Commit 7b71607

Browse files
authored
fix(vue): replacing routes across nested outlets preserves previous route info (#25171)
resolves #25017
1 parent a6a772a commit 7b71607

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

packages/vue-router/src/locationHistory.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ export const createLocationHistory = () => {
66

77
const add = (routeInfo: RouteInfo) => {
88
switch (routeInfo.routerAction) {
9-
case "replace":
10-
replaceRoute(routeInfo);
11-
break;
129
case "pop":
1310
pop(routeInfo);
1411
break;
@@ -41,13 +38,6 @@ export const createLocationHistory = () => {
4138
}
4239
}
4340

44-
const replaceRoute = (routeInfo: RouteInfo) => {
45-
const routeInfos = getTabsHistory(routeInfo.tab);
46-
routeInfos && routeInfos.pop();
47-
locationHistory.pop();
48-
addRoute(routeInfo);
49-
}
50-
5141
const pop = (routeInfo: RouteInfo) => {
5242
const tabHistory = getTabsHistory(routeInfo.tab);
5343
let ri;

packages/vue/test-app/src/views/RouterOutlet.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<ion-header>
44
<ion-toolbar>
55
<ion-buttons slot="start">
6+
<ion-back-button id="routeroutlet-back-button" text="Back to main outlet"></ion-back-button>
67
<ion-button id="inbox" router-link="/nested/inbox" router-direction="root">Inbox</ion-button>
78
<ion-button id="trash" router-link="/nested/trash" router-direction="root">Trash</ion-button>
89
<ion-button id="outbox" router-link="/nested/outbox" router-direction="root">Outbox</ion-button>
@@ -19,6 +20,7 @@
1920

2021
<script lang="ts">
2122
import {
23+
IonBackButton,
2224
IonHeader,
2325
IonButtons,
2426
IonButton,
@@ -31,6 +33,7 @@ import { defineComponent } from 'vue';
3133
3234
export default defineComponent({
3335
components: {
36+
IonBackButton,
3437
IonHeader,
3538
IonButtons,
3639
IonButton,

packages/vue/test-app/tests/e2e/specs/nested.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ describe('Nested', () => {
44
cy.ionPageVisible('nestedchild');
55
});
66

7-
it('should show first page', () => {
8-
cy.ionPageVisible('nestedchild');
9-
});
10-
117
it('should go to second page', () => {
128
cy.get('#nested-child-two').click();
139
cy.ionPageVisible('nestedchildtwo');
@@ -21,8 +17,6 @@ describe('Nested', () => {
2117
});
2218

2319
it('should go navigate across nested outlet contexts', () => {
24-
cy.ionPageVisible('nestedchild');
25-
2620
cy.get('#nested-tabs').click();
2721

2822
cy.ionPageHidden('routeroutlet');
@@ -34,3 +28,25 @@ describe('Nested', () => {
3428
cy.ionPageVisible('routeroutlet');
3529
});
3630
})
31+
32+
describe('Nested - Replace', () => {
33+
it('should replace a route but still be able to go back to main outlet', () => {
34+
cy.visit('http://localhost:8080');
35+
36+
cy.routerPush('/nested');
37+
cy.ionPageHidden('home');
38+
cy.ionPageVisible('nestedchild');
39+
40+
cy.routerReplace('/nested/two');
41+
cy.ionPageDoesNotExist('nestedchild');
42+
cy.ionPageVisible('nestedchildtwo');
43+
44+
/**
45+
* ionBackClick does not handle nested pages
46+
* with multiple back buttons
47+
*/
48+
cy.get('#routeroutlet-back-button').click();
49+
cy.ionPageDoesNotExist('nestedchildtwo');
50+
cy.ionPageVisible('home');
51+
})
52+
})

0 commit comments

Comments
 (0)