Skip to content

Commit

Permalink
fix(vue): correct route is replaced when using router.replace (#24533)
Browse files Browse the repository at this point in the history
resolves #24226
  • Loading branch information
liamdebeasi committed Jan 10, 2022
1 parent f539ff4 commit 90458da
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/vue-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,19 @@ export const createIonRouter = (opts: IonicVueRouterOptions, router: Router) =>
const lastRoute = locationHistory.getCurrentRouteInfoForTab(routeInfo.tab);
routeInfo.pushedByRoute = lastRoute?.pushedByRoute;
} else if (routeInfo.routerAction === 'replace') {
const currentRouteInfo = locationHistory.last();

/**
* When replacing a route, we want to make sure we select the current route
* that we are on, not the last route in the stack. The last route in the stack
* is not always the current route.
* Example:
* Given the following history: /page1 --> /page2
* Doing router.go(-1) would bring you to /page1.
* If you then did router.replace('/page3'), /page1 should
* be replaced with /page3 even though /page2 is the last
* item in the stack/
*/
const currentRouteInfo = locationHistory.current(initialHistoryPosition, currentHistoryPosition);

/**
* If going from /home to /child, then replacing from
Expand Down
21 changes: 21 additions & 0 deletions packages/vue/test-app/tests/e2e/specs/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,27 @@ describe('Routing', () => {
cy.ionPageVisible('routingparameterview');
cy.ionPageDoesNotExist('routingchild');
})

// Verifies fix for https://github.com/ionic-team/ionic-framework/issues/24226
it('should correctly replace a route after popping', () => {
cy.visit('http://localhost:8080');

cy.routerPush('/routing');
cy.ionPageVisible('routing');
cy.ionPageHidden('home');

cy.routerGo(-1);
cy.ionPageVisible('home');
cy.ionPageDoesNotExist('routing');

cy.routerReplace('/inputs');
cy.ionPageVisible('inputs');
cy.ionPageDoesNotExist('home');

cy.routerPush('/');
cy.ionPageVisible('home');
cy.ionPageHidden('inputs');
})
});

describe('Routing - Swipe to Go Back', () => {
Expand Down

0 comments on commit 90458da

Please sign in to comment.