Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): fix route navigation, close #1514 #1527

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading