-
-
Notifications
You must be signed in to change notification settings - Fork 2.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
Changing URL hash causes entire page to reload #1801
Comments
This depends on how you're changing the url. If you're directly changing the URL from browser, obviously it will reload. If you're changing the route programmatically, then you need to use the exposed router ( |
The thing is - Docusaurus, for example, works perfectly fine with Fancybox, but Vitepress does not, simply because it reloads on hash change, when navigating using back/forward button or changing URL manually. I do not understand your comment - "obviously it will reload". Steps to reproduce on Docusaurus:
So, I am sure there is a difference between React and Vue routing, and I would like to make Vitepress to work the same as Docusaurus. |
Ah, this works on VuePress too 👀 . But VuePress/Docusaurus have probably much more complex router. Our router only intercepts certain kind of stuff, browser does the most of the thing. PS: if you just want fancybox for zooming images, the workarounds mentioned here might work #854 |
Yes, you are right, VuePress works the way I want. If Vitpress worked the same way, then anyone using a third part scripts with hash navigation would benefit. p.s. I already use Fancybox on my main site, I just wanted to create a documentation site and use it here as well. It works well if I disable Hash plugin, but I would like to avoid doing that. p.p.s I love Vite and VitePress, thank you all for your great work! |
FYI, I hacked the VitePress source code for fun and found this problem to be very easy to fix. So, the problem is here: window.addEventListener('popstate', (e) => {
loadPage(location.href, (e.state && e.state.scrollPosition) || 0)
}) As you can see, VitePress loads page every time the user navigates using the browser's back/forward buttons. I added a simple check to avoid reloading current page. I could not find out how to get location of previous page, so I created a global variable and stored |
There are now router guards that should be sufficient for these cases. Refer #2564 |
Describe the bug
Changing URL hash causes entire page to reload. This causes issues with third part script that uses hash navigation (well, it is Fancybox, but it is not relevant, you can quickly observe that by yourself).
Reproduction
Expected behavior
The page should not reload
System Info
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: