-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
replaceState Error when path starts with // and scrollBehavior is set #2593
Comments
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 |
I faced this issue too. Steps to reproduce:
Debug info
function setupScroll () {
// Fix for #1585 for Firefox
// Fix for #2195 Add optional third attribute to workaround a bug in safari https://bugs.webkit.org/show_bug.cgi?id=182678
window.history.replaceState({ key: getStateKey() }, '', window.location.href.replace(window.location.origin, '')); // ======> This line cause the issue
window.addEventListener('popstate', function (e) {
saveScrollPosition();
if (e.state && e.state.key) {
setStateKey(e.state.key);
}
});
} The temporary solution: const Router = new VueRouter({
scrollBehavior: () => ({ y: 0 }), // ===> Comment this line to avoid setupScroll => Then implement scrollbehavior by your self on route change.
routes: ...,
}) If you ignore Hope this help! |
wow, thanks for this issue. Just faced this as well, exact same scenario as @luatnd desribed. |
@posva any news about this? |
Hi, |
I'm also seeing this problem, but with $ sign in the querystring. |
I'm experiencing this problem as well. In my case the original URL looks like This comment has some useful info: remix-run/react-router#3184 (comment) |
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:
|
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 |
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 I think the issue is caused by this line, as @mattheyan mentioned. When the pathname contains multiple leading slashes, the 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) |
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'
The text was updated successfully, but these errors were encountered: