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

[full-ci] Vue3: Update vue-router #8215

Merged
merged 18 commits into from
Jan 17, 2023
Merged
Changes from 1 commit
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
23 changes: 15 additions & 8 deletions packages/web-runtime/src/router/patchCleanPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@ import get from 'lodash-es/get'
// should immediately go away and be removed after finalizing the update
// to apply the patch to a route add meta.patchCleanPath = true to it
// to patch needs to be enabled on a route level, to do so add meta.patchCleanPath = true property to the route
// c.f. https://github.com/vuejs/router/issues/ 1638
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove blank in url please ;-)

export const patchRouter = (router: Router) => {
const bindMatcher = router.match.bind(router)
const bindResolver = router.resolve.bind(router)
const cleanPath = (route) =>
[
['%2F', '/'],
['//', '/']
].reduce((path, rule) => path.replaceAll(rule[0], rule[1]), route || '')

router.match = (raw, current, redirectFrom) => {
const bindMatch = bindMatcher(raw, current, redirectFrom)
router.resolve = (
raw: RouteLocationRaw,
currentLocation?: RouteLocationNormalizedLoaded
): RouteLocation & {
href: string
} => {
const bindResolve = bindResolver(raw, currentLocation)

if (!get(bindMatch, 'meta.patchCleanPath', false)) {
return bindMatch
if (!get(bindResolve, 'meta.patchCleanPath', false)) {
return bindResolve
}

return {
...bindMatch,
path: cleanPath(bindMatch.path),
fullPath: cleanPath(bindMatch.fullPath)
...bindResolve,
href: cleanPath(bindResolve.href),
path: cleanPath(bindResolve.path),
fullPath: cleanPath(bindResolve.fullPath)
}
}

Expand Down