-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
slashes should not be encoded for catch all regexes #1638
Comments
This behavior is intended for regular params like Note to myself in edit comment |
Hey, thanks for the reply. Hopefully one day I can contribute a bug fix PR myself. For now, is there any workaround that you can suggest while I wait for the official fix? |
Hi, is there any update to this? |
Here's a workaround that we/I've come up with - it's not perfect as it's applied to the whole path, so we enable it only for routes with import { RouteLocation, RouteLocationNormalizedLoaded, RouteLocationRaw, Router } from 'vue-router'
export const patchRouter = (router: Router) => {
const cleanPath = (route) =>
[
['%2F', '/'],
['//', '/']
].reduce((path, rule) => path.replaceAll(rule[0], rule[1]), route || '')
const bindResolve = router.resolve.bind(router)
router.resolve = (
raw: RouteLocationRaw,
currentLocation?: RouteLocationNormalizedLoaded
): RouteLocation & {
href: string
} => {
const resolved = bindResolve(raw, currentLocation)
if (resolved.meta?.patchCleanPath !== true) {
return resolved
}
return {
...resolved,
href: cleanPath(resolved.href),
path: cleanPath(resolved.path),
fullPath: cleanPath(resolved.fullPath)
}
}
const routerMethodFactory = (method) => (to) => {
const resolved = router.resolve(to)
if (resolved.meta?.patchCleanPath !== true) {
return method(to)
}
return method({
path: cleanPath(resolved.fullPath),
query: resolved.query
})
}
router.push = routerMethodFactory(router.push.bind(router))
router.replace = routerMethodFactory(router.replace.bind(router))
return router
} |
Hey, thanks for your patch. Will try it out. It is very appreciated. |
If you find any edge cases that don't work, I'm happy to hear. |
Your patch works. Good enough for us to ship the site for now. Thank you so much @dschmidt. |
This applies to all custom regex routes which match a slash or contain one in their literal part fixes vuejs#1638
Same issue, it seems it doesn't happen when you use something like |
Version
4.1.6
Reproduction link
codesandbox.io
Steps to reproduce
router.replace({ hash: '#something' })
.(https://domain.com/about.html#yippy)
.https://domain.com/test%2Fdeep%2Fabout.html#yaya
.What is expected?
Url to become
https://domain.com/test/deep/about.html#yaya
What is actually happening?
Url became
https://domain.com/test%2Fdeep%2Fabout.html#yaya
This is for the front-end of a CMS-supported project, where the front part of the URL is controlled by the CMS and it varies depending on the environment. Hence the need to first match it using
:pathMatch()
then match the actual page to render using:pageName()
.Also, all pages has to be suffixed with .html, hence I am using a (kind of) complex regex to match the page. It works, however, I stumble upon this issue.
The text was updated successfully, but these errors were encountered: