Skip to content

Commit e6455e0

Browse files
authoredApr 8, 2024··
fix(client): keep full path during route navigation (close #1514) (#1527)
1 parent c4437d4 commit e6455e0

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed
 

‎e2e/docs/router/navigation.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<button id="home" @click="goHome">Home</button>
2+
<button id="404" @click="go404">404</button>
3+
4+
<script setup lang="ts">
5+
import { useRouter } from 'vuepress/client';
6+
7+
const router = useRouter();
8+
9+
const goHome = () => {
10+
router.push('/?home=true');
11+
}
12+
13+
const go404 = () => {
14+
router.push('/404.html#404');
15+
}
16+
</script>

‎e2e/tests/router/navigation.cy.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
it('should preserve query', () => {
2+
const E2E_BASE = Cypress.env('E2E_BASE')
3+
4+
cy.visit('/router/navigation.html')
5+
6+
cy.get('#home').click()
7+
8+
cy.location('pathname').should('eq', E2E_BASE)
9+
cy.location('search').should('eq', '?home=true')
10+
})
11+
12+
it('should preserve hash', () => {
13+
const E2E_BASE = Cypress.env('E2E_BASE')
14+
15+
cy.visit('/router/navigation.html')
16+
17+
cy.get('#404').click()
18+
19+
cy.location('pathname').should('eq', `${E2E_BASE}404.html`)
20+
cy.location('hash').should('eq', '#404')
21+
})

‎packages/client/src/router/createVueRouter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export const createVueRouter = (): Router => {
4040
// and save page data to route meta
4141
router.beforeResolve(async (to, from): Promise<string | void> => {
4242
if (to.path !== from.path || from === START_LOCATION) {
43-
const route = resolveRoute(to.path)
43+
const route = resolveRoute(to.fullPath)
4444

45-
if (route.path !== to.path) {
45+
if (route.path !== to.fullPath) {
4646
return route.path
4747
}
4848
const pageChunk = await route.loader()

0 commit comments

Comments
 (0)
Please sign in to comment.