Router: Link to hash id doesn't scroll to element

Created on 6 Aug 2018  路  3Comments  路  Source: reach/router

This is a combination of a bug report and question, I've run into a problem when using Link with a hash value.

Like this

<Link to="#foo">Foo</Link>

then I'd expect element with a foo id to enter the viewport (like a native link behaves) but right now nothing happens except that the url updates.

I'm guessing that the preventDefault is causing the issue here https://github.com/reach/router/blob/317a679c1975e32b4096880a140defc9489064ac/src/index.js#L390-L393

Is this an intended behavior or a bug? I'd be happy to provide a PR fixing this.

enhancement

Most helpful comment

I think there are use cases for when you'd want that. Like the reactjs.org website on the /tutorial page. In the sidebar you want to be able to check which links are active etc.

Gatsby has implemented custom behavior to solve this but it would be nice have this in core

All 3 comments

Why do you need Linkwith anchor? You can just use <a> in this case.

I think there are use cases for when you'd want that. Like the reactjs.org website on the /tutorial page. In the sidebar you want to be able to check which links are active etc.

Gatsby has implemented custom behavior to solve this but it would be nice have this in core

You can just use <a> in this case

In won't trigger location change

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thupi picture thupi  路  4Comments

jsonmaur picture jsonmaur  路  4Comments

EJIqpEP picture EJIqpEP  路  4Comments

Kadrian picture Kadrian  路  5Comments

ricardobrandao picture ricardobrandao  路  5Comments