loteoo / hyperstatic

Routing, prerendering, code splitting and prefetching for hyperapp
https://hyperstatic.dev/
MIT License
59 stars 5 forks source link

Jump to top when using <Link> #13

Open mdings opened 4 years ago

mdings commented 4 years ago

When building links with the builtin Link-component I notice that the page doesn't automatically scroll back to the top when rendered. Is there an action or effect that we can overwrite to do something like document.scrollTop = '0px'?

mdings commented 4 years ago

I fixed this now using a navigation subscriber with a location.href mutation observer. However, now the page jumps to the top on every new page vies. Also when using the back-button which is not intended behaviour. Do you know of a more robust way to implement this?

Oh, btw: I just launched my site using Hyperstatic 🎉. It is hosted in Netlify as well: https://www.meetsoil.com (In Dutch for now only..)

loteoo commented 4 years ago

Hey @mdings !! Thanks for creating this issue! This is something I had not thought of.

Sorry for the delayed response.

I made the changes here, do you have any comments on them? https://github.com/loteoo/hyperstatic/pull/15

Also, WOW that's a beautiful website. So glad someone experienced is using hyperstatic for it's website :)

Let me know of any ideas / improvements you have in mind!!!

mdings commented 4 years ago

Hey @loteoo,

Sorry for the delayed response

That's alright. Thanks for getting back to this. I've seen the PR and it's looking good for what I want to achieve. However, this might not be the case for other people. Can we make this functionality a bit more robust, so that we can override it when needed? With this piece of code the page will also scroll back to the top when hitting the back-button. Maybe you can add an API to the source that let's us overwrite pieces from the source. In the end, that is what adds the flexibility in my opinion.