Skip to content

Commit

Permalink
fix(client): keep full path during route navigation (close #1514) (#1527
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Mister-Hope authored Apr 8, 2024
1 parent c4437d4 commit e6455e0
Show file tree
Hide file tree
Showing 3 changed files with 39 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 'vuepress/client';

const router = useRouter();

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

const go404 = () => {
router.push('/404.html#404');
}
</script>
21 changes: 21 additions & 0 deletions e2e/tests/router/navigation.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
it('should preserve query', () => {
const E2E_BASE = Cypress.env('E2E_BASE')

cy.visit('/router/navigation.html')

cy.get('#home').click()

cy.location('pathname').should('eq', E2E_BASE)
cy.location('search').should('eq', '?home=true')
})

it('should preserve hash', () => {
const E2E_BASE = Cypress.env('E2E_BASE')

cy.visit('/router/navigation.html')

cy.get('#404').click()

cy.location('pathname').should('eq', `${E2E_BASE}404.html`)
cy.location('hash').should('eq', '#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 e6455e0

Please sign in to comment.