vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
4.37k stars 350 forks source link

Anchors and Hashchange are impossible to use #418

Closed rawb1t closed 2 years ago

rawb1t commented 2 years ago

Description

It is completely impossible to use simple anchors with this plugin. Neither the hashchange event nor a simple location.hash modify is possible since it always throws an error that I should use the vite-plugin-ssr. But there is not a single function to react to hashchanges, navigate to a hash or any kind of documentation.

I don't believe that this is supposed to be.

How can I fix that?

Error Stack

assert.js:40 Uncaught Error: [vite-plugin-ssr@0.4.19][Wrong Usage] Manipulating `window.history.state` is forbidden (only vite-plugin-ssr is allowed to). Does one of your library try to manipulate it?
brillout commented 2 years ago

I agree this is something that should be fixed.

It's a regression introduced by https://github.com/brillout/vite-plugin-ssr/commit/510501b5d2757bc6e2be191ee07ce3d70c7b6797.

Does your use case work with 0.4.18?

brillout commented 2 years ago

Also, what is your use case?

rawb1t commented 2 years ago

I am developing a Single Page Presentation Website with animated scrolling between the sections. The Problem is that navigate doesn't fire the hashchange listener when loading the site together with an anchor. I managed to do some workarounds but I think it would be great if there is a way to handle Anchors.

Btw: I am using client side navigation!

brillout commented 2 years ago

The Problem is that navigate doesn't fire the hashchange listener when loading the site together with an anchor.

That seems unrelated to vps though.

That said, I do think vps can improve anchor use cases. I'll have a look at this.

rawb1t commented 2 years ago

That would be great! Thank you!

brillout commented 2 years ago

Fix released in 0.4.21. You should now be able to seamlessly use hash navigation. Let me know if something doesn't work.

(Btw. https://github.com/sponsors/brillout in case that's something you(r company) would be interested in.)

rawb1t commented 2 years ago

Seems to work, thank you!