navi icon indicating copy to clipboard operation
navi copied to clipboard

<Link> scrolls to top on mobile

Open bouiboui opened this issue 4 years ago • 4 comments

Hi, on mobile, when I click on <Link> elements, the window scrolls to the top of the page, but what I really want is to update the history without scrolling.

If I replace the Link element with:

<button onClick={() => window.history.pushState(null, document.title, linkProps.href)}>

I get close to what I really want (but it's dirty).

Do you know any way to prevent this behaviour?

Thank you.

bouiboui avatar Feb 27 '20 20:02 bouiboui

This is currently the expected behavior, as Navi is mainly focused at websites.

I'm curious – are you using Navi to build an app instead of a mobile web site? If so, I can see how this behavior may get in the way. I'm not sure off the top of my head how I'd fix this, but it may make sense to add some sort of configuration option...

jamesknelson avatar Mar 29 '20 09:03 jamesknelson

Thanks for your answer, I'm using it on a website where there is a list of items, each item has a button that opens a modal, when I open the modal I want the URL to change to the item's own URL. When I close the modal, I want the URL to change back to the list URL.

But when there's hundred of items and you scrolled to the bottom of the list, clicking on the modal open button brings you back to the top of the list, which is unfortunate.

bouiboui avatar Mar 29 '20 18:03 bouiboui

I see, that makes sense. I'm not exactly sure of the best way to go about this.

I'm personally of the opinion that modals usually shouldn't have their own URLs, but I can also see how others may come to a different conclusion. Perhaps it would make sense to add some sort of prop to <Link> that disabled scrolling?

jamesknelson avatar Mar 30 '20 06:03 jamesknelson

Do other routers provide the option / act like this?

bouiboui avatar Mar 30 '20 08:03 bouiboui