-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Labels
bugfixed on 4.xThis issue has been already fixed on the v4 but exists in v3This issue has been already fixed on the v4 but exists in v3
Description
Version
3.0.2
Reproduction link
https://github.com/yegorLitvinov/vue-router-bug
Steps to reproduce
Set scrollBehavior property in router config. Put two forward slashes into beginning of the url (e.g. http://localhost:8081//about)
What is expected?
No errors in console
What is actually happening?
In firefox: SecurityError: The operation is insecure.
In Chrome: Uncaught DOMException: Failed to execute 'replaceState' on 'History': A history state object with URL 'http://about/' cannot be created in a document with origin 'http://localhost:8081' and URL 'http://localhost:8081//about'
makaria, Tsuyoshi84, bp2008, bkarlson, klr and 3 more
Metadata
Metadata
Assignees
Labels
bugfixed on 4.xThis issue has been already fixed on the v4 but exists in v3This issue has been already fixed on the v4 but exists in v3
Activity
[-]SecurityError when url contains // and scrollBehavior is set[/-][+]replaceState Error when url contains // and scrollBehavior is set[/+][-]replaceState Error when url contains // and scrollBehavior is set[/-][+]replaceState Error when path starts with // and scrollBehavior is set[/+]posva commentedon Jan 22, 2019
It looks like we should sanitize the beginning of the URL so it doesn't contain trailing slashes but I'm still unsure about it. I will have to search a bit more
luatnd commentedon May 21, 2019
I faced this issue too.
Steps to reproduce:
primary.domain.com
secondary.domain.com
<base href="https://primary.domain.com" target="_blank">
intosecondary.domain.com
secondary.domain.com
then saw this issueDebug info
vue-router/dist/vue-router.js:1550
The temporary solution:
Comment the bellow line to avoid setupScroll => Then implement scrollBehavior by your self on route changed:
If you ignore
scrollBehavior
key, setupScroll() will not be executed.Hope this help!
feat(app): Allow forcing publicPath on dev mode too (for SPA and PWA …
bkarlson commentedon Nov 7, 2019
wow, thanks for this issue. Just faced this as well, exact same scenario as @luatnd desribed.
ralf57 commentedon Nov 20, 2019
@posva any news about this?
Aigrefin commentedon Feb 3, 2020
Hi,
The temporary solution from @luatnd doesn't always work.
Any progress on this bug ?
Madd0g commentedon Feb 21, 2020
I'm also seeing this problem, but with $ sign in the querystring.
mattheyan commentedon May 8, 2020
I'm experiencing this problem as well.
In my case the original URL looks like
https://site.com//?x=y
, which results in callingreplaceState
with//?x=y
as the URL. I put in a place a workaround to detect the situation and trim the duplicate/
before initializing the router.This comment has some useful info: remix-run/react-router#3184 (comment)
Note that although I'm linking to an issue in a react package, I am actually experiencing this issue in vue router. 😛 It seems this same issue is referenced in lots of different contexts, so it must be a common / easy problem to run into. Either that or different libs have based their browser history code on the same original source.
HaydenBruin commentedon Dec 8, 2020
I was having this issue as well. The only thing I was using scrollBehavior for was to scroll the user to the top of the page.
Before:
After:
posva commentedon Apr 14, 2021
In v4 this is fixed by using the full URL: https://github.com/vuejs/vue-router-next/blob/master/src/history/html5.ts#L220
I think it's worth adding the same fix here
snoozbuster commentedon Dec 15, 2021
hey @posva - I don't think this is closed by the linked PR. That PR does fix the issue if the navigation comes from a router-link or programmatic call to
replace()
orpush()
- but the issue still remains if the page is hard-loaded with a double-slash in the pathname.I think the issue is caused by this line, as @mattheyan mentioned. When the pathname contains multiple leading slashes, the
absoluteUrl
with the scheme and hostname excised contains a leading double slash, which is reinterpreted as an actual absolute URL (with current scheme, host and path) instead of a path on the current domain.cleanPath
isn't ever called on this URL, so the fix in that PR doesn't actually fix this issue.I imagine the easiest way to fix this is to update the code to call cleanPath here. assuming that's the correct solution, I've taken the liberty of opening a PR for it: #3679 (with included e2e test)