vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.16k stars 922 forks source link

fix: fix route resolving error with hash and queries (close #1561) #1562

Closed pengzhanbo closed 1 month ago

pengzhanbo commented 1 month ago

Before submitting the PR, please make sure you do the following

What is the purpose of this pull request?

Description

fix: #1561

coveralls commented 1 month ago

Pull Request Test Coverage Report for Build 9248171287

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/client/src/router/resolveRouteFullPath.ts 0 3 0.0%
packages/client/src/router/resolveRoute.ts 0 5 0.0%
packages/client/src/router/resolveRoutePath.ts 0 9 0.0%
<!-- Total: 8 25 32.0% -->
Totals Coverage Status
Change from base Build 9211217292: -0.1%
Covered Lines: 690
Relevant Lines: 1721

💛 - Coveralls
digital-codes commented 1 month ago

changing fullPath to path in client/dist/app.js like so fixes the issue with query strings ... router.beforeResolve(async (to, from) => { if (to.path !== from.path || from === START_LOCATION) { const route = resolveRoute(to.path); ...

Not sure what's the exact difference and why it worked up to rc8 (at least) and broke with rc11 Also not sure about side effects ...

you have const fullPath = to.fullPath.split('#')[0]

Will fix hash but not query parms, right?

pengzhanbo commented 1 month ago

changing fullPath to path in client/dist/app.js like so fixes the issue with query strings ... router.beforeResolve(async (to, from) => { if (to.path !== from.path || from === START_LOCATION) { const route = resolveRoute(to.path); ...

Not sure what's the exact difference and why it worked up to rc8 (at least) and broke with rc11 Also not sure about side effects ...

you have const fullPath = to.fullPath.split('#')[0]

Will fix hash but not query parms, right?

The bug was caused by the fact that vuepress internally needs to resolve the route to obtain the route instance through pathname, but route.fullPath contains pathname, query, hash, and other content, leading to parsing errors and failure to match the route instance.

You can refer to the changes made in this PR submission for more information.

Mister-Hope commented 1 month ago

I updated the pr to improve the original fix performance.

Also now API are unified to avoid misleading.