Skip to content

Commit

Permalink
fix(client): fix route navigation, close #1514
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 6, 2024
1 parent 950f158 commit 9ecfa59
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
16 changes: 16 additions & 0 deletions e2e/docs/router/navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<button id="home" @click="goHome">Home</button>
<button id="404" @click="go404">404</button>

<script setup lang="ts">
import { useRouter } from 'vue-router';

const router = useRouter();

const goHome = () => {
router.push('/?home=true');
}

const go404 = () => {
router.push('/404.html#404');
}
</script>
19 changes: 19 additions & 0 deletions e2e/tests/router/navigation.cy.ts
Original file line number Diff line number Diff line change
@@ -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`)
})
4 changes: 2 additions & 2 deletions packages/client/src/router/createVueRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const createVueRouter = (): Router => {
// and save page data to route meta
router.beforeResolve(async (to, from): Promise<string | void> => {
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()
Expand Down

0 comments on commit 9ecfa59

Please sign in to comment.