react-scroll icon indicating copy to clipboard operation
react-scroll copied to clipboard

How to scroll with hash? Example is empty

Open tr1s opened this issue 4 years ago • 6 comments

I'm trying to learn how to push the target to the url when I click an element, so the webpage can also scroll to the right element when the hash is in the url... I think I can achieve this by using the hash, but the example is showing up with a blank sandbox...

https://codesandbox.io/s/y0zzrk1v1j

Any ideas on how to achieve this?

I'm using Gatsby

tr1s avatar Sep 27 '19 16:09 tr1s

Any update on this? Would be useful... It's probably not very hard to code myself, but there should be a way to do it with this package, no?

luke-m avatar Apr 08 '21 11:04 luke-m

Hi,

There is an example section in the repo.

https://github.com/fisshy/react-scroll/tree/master/examples/with-hash

fisshy avatar Apr 08 '21 12:04 fisshy

Any chance to get a codesandbox.io link for this? Considering the one in the documentation is dead...

luke-m avatar Apr 08 '21 13:04 luke-m

I tried it out in the "basic example" sandbox.io page because that seems to contain an anchor link as well and it doesn't work. My expectation is that when I open the page with a hash URL parameter (i.e. web.site/subpage#anchor), the page is scrolled to the section with the ID anchor. That doesn't work for me.

luke-m avatar Apr 12 '21 09:04 luke-m

https://codesandbox.io/s/basic-forked-8jje2?file=/src/index.js

I created one simple here for you.

fisshy avatar Apr 12 '21 10:04 fisshy

I see, thanks. The important part is giving the ID to a standard <div> instead of an <Element>, then it works.

luke-m avatar Apr 12 '21 13:04 luke-m