From 9ecfa598e2132256152c63ca7f213019d05e4bba Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Sun, 7 Apr 2024 01:16:28 +0800 Subject: [PATCH 1/2] fix(client): fix route navigation, close #1514 --- e2e/docs/router/navigation.md | 16 ++++++++++++++++ e2e/tests/router/navigation.cy.ts | 19 +++++++++++++++++++ packages/client/src/router/createVueRouter.ts | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 e2e/docs/router/navigation.md create mode 100644 e2e/tests/router/navigation.cy.ts diff --git a/e2e/docs/router/navigation.md b/e2e/docs/router/navigation.md new file mode 100644 index 0000000000..7357a2943e --- /dev/null +++ b/e2e/docs/router/navigation.md @@ -0,0 +1,16 @@ + + + + diff --git a/e2e/tests/router/navigation.cy.ts b/e2e/tests/router/navigation.cy.ts new file mode 100644 index 0000000000..48534ae063 --- /dev/null +++ b/e2e/tests/router/navigation.cy.ts @@ -0,0 +1,19 @@ +it('should preserve query', () => { + const E2E_BASE = Cypress.env('E2E_BASE') + + cy.visit('/router/navigation.html') + + cy.get('#home').click() + + cy.location().eq(`${E2E_BASE}?home=true`) +}) + +it('should preserve hash', () => { + const E2E_BASE = Cypress.env('E2E_BASE') + + cy.visit('/router/navigation.html') + + cy.get('#404').click() + + cy.location().eq(`${E2E_BASE}404.html#404`) +}) diff --git a/packages/client/src/router/createVueRouter.ts b/packages/client/src/router/createVueRouter.ts index d12be64782..a9dd605096 100644 --- a/packages/client/src/router/createVueRouter.ts +++ b/packages/client/src/router/createVueRouter.ts @@ -40,9 +40,9 @@ export const createVueRouter = (): Router => { // and save page data to route meta router.beforeResolve(async (to, from): Promise => { if (to.path !== from.path || from === START_LOCATION) { - const route = resolveRoute(to.path) + const route = resolveRoute(to.fullPath) - if (route.path !== to.path) { + if (route.path !== to.fullPath) { return route.path } const pageChunk = await route.loader() From b6107eb2f36c84917d55d8b1ba2b8c571e651620 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Sun, 7 Apr 2024 23:50:40 +0800 Subject: [PATCH 2/2] test: fix e2e test --- e2e/docs/router/navigation.md | 2 +- e2e/tests/router/navigation.cy.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/e2e/docs/router/navigation.md b/e2e/docs/router/navigation.md index 7357a2943e..2df4da53cb 100644 --- a/e2e/docs/router/navigation.md +++ b/e2e/docs/router/navigation.md @@ -2,7 +2,7 @@