From d4fe6409285f92a285b23aa961caf7432882ffc7 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Mon, 28 Jun 2021 15:25:48 +0000 Subject: [PATCH 1/2] params now match to new views, updated tests --- packages/vue-router/src/viewStacks.ts | 40 ++++++---------- .../test-app/src/views/RoutingParameter.vue | 2 +- .../vue/test-app/tests/e2e/specs/routing.js | 46 +++++++++++++------ .../test-app/tests/e2e/support/commands.js | 1 - .../vue/test-app/tests/unit/routing.spec.ts | 4 +- 5 files changed, 51 insertions(+), 42 deletions(-) diff --git a/packages/vue-router/src/viewStacks.ts b/packages/vue-router/src/viewStacks.ts index 3b891137259..15a48857049 100644 --- a/packages/vue-router/src/viewStacks.ts +++ b/packages/vue-router/src/viewStacks.ts @@ -23,31 +23,7 @@ export const createViewStacks = (router: Router) => { } const findViewItemByRouteInfo = (routeInfo: RouteInfo, outletId?: number) => { - let viewItem = findViewItemByPath(routeInfo.pathname, outletId, false); - - /** - * Given a route such as /path/:id, - * going from /page/1 to /home - * to /page/2 will cause the same - * view item from /page/1 to match - * for /page/2 so we need to make - * sure any params get updated. - * Not normally an issue for accessing - * the params via useRouter from vue-router, - * but when passing params as props not doing - * this would cause the old props to show up. - */ - if (viewItem && viewItem.params !== routeInfo.params) { - /** - * Clear the props function result - * as the value may have changed due - * to different props. - */ - delete viewItem.vueComponentData.propsFunctionResult; - viewItem.params = routeInfo.params; - } - - return viewItem; + return findViewItemByPath(routeInfo.pathname, outletId, false); } const findLeavingViewItemByRouteInfo = (routeInfo: RouteInfo, outletId?: number, mustBeIonRoute: boolean = true) => { @@ -81,6 +57,20 @@ export const createViewStacks = (router: Router) => { const findMatchedRoute = resolvedPath.matched.find((matchedRoute: RouteLocationMatched) => matchedRoute === viewItem.matchedRoute); if (findMatchedRoute) { + + /** + * /page/1 and /page/2 should not match + * to the same view item otherwise there will + * be not page transition and we will need to + * explicitly clear out parameters from page 1 + * so the page 2 params are properly passed + * to the developer's app. + */ + const hasParameter = findMatchedRoute.path.includes(':'); + if (hasParameter && path !== viewItem.pathname) { + return false; + } + return viewItem; } diff --git a/packages/vue/test-app/src/views/RoutingParameter.vue b/packages/vue/test-app/src/views/RoutingParameter.vue index ffeac7f0f08..36c74e2fcc9 100644 --- a/packages/vue/test-app/src/views/RoutingParameter.vue +++ b/packages/vue/test-app/src/views/RoutingParameter.vue @@ -1,5 +1,5 @@