From: Eduardo San Martin Morote Date: Wed, 27 Jul 2022 10:06:33 +0000 (+0200) Subject: fix: avoid restore on cancelled pop navigations X-Git-Tag: v4.1.3~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66491c1fb56de924337ac35a0d235e662d138480;p=thirdparty%2Fvuejs%2Frouter.git fix: avoid restore on cancelled pop navigations --- diff --git a/packages/router/e2e/guards-instances/index.ts b/packages/router/e2e/guards-instances/index.ts index 984ad44c..e792b193 100644 --- a/packages/router/e2e/guards-instances/index.ts +++ b/packages/router/e2e/guards-instances/index.ts @@ -96,11 +96,14 @@ function createTestComponent(key: string) { } const Foo = createTestComponent('Foo') -const Bar = createTestComponent('Bar') const One = createTestComponent('One') const Two = createTestComponent('Two') const Aux = createTestComponent('Aux') +const WithId = defineComponent({ + template: `

id: {{ $route.params.id }}

`, +}) + const webHistory = createWebHistory('/guards-instances') const router = createRouter({ history: webHistory, @@ -117,7 +120,8 @@ const router = createRouter({ // TODO: test that the onBeforeRouteUpdate isn't kept { path: '/b/:id', - component: Bar, + name: 'id', + component: WithId, }, { path: '/named-one', @@ -136,6 +140,17 @@ const router = createRouter({ ], }) +router.beforeEach(async (to, from) => { + if (to.name === 'id') { + const toId = Number(to.params.id) + const fromId = Number(from.params.id) + // only do it when we are going backwards + if (!Number.isNaN(toId) && !Number.isNaN(fromId) && toId < fromId) { + await new Promise(r => setTimeout(r, 250)) + } + } +}) + // preserve existing query const originalPush = router.push router.push = to => { @@ -187,6 +202,9 @@ leaves: {{ state.leave }}
  • {{ route.fullPath }}
  • /named-one
  • /named-two
  • +
  • /b/1
  • +
  • /b/2
  • +
  • /b/3