Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix <Link hash> #2216

Closed
aszwemin opened this issue Oct 9, 2015 · 6 comments
Closed

Fix <Link hash> #2216

aszwemin opened this issue Oct 9, 2015 · 6 comments
Labels

Comments

@aszwemin
Copy link

aszwemin commented Oct 9, 2015

I have two links, one created with <Link to='/faq' hash='#whatis'> and the other one created with <a href='/faq#whereq'> that look as following when inspecting element on rendered document:

<a class="" href="/faq#whatis" data-reactid=".0.2.0.0.0.1.0">...</a>
<a href="/faq#whereq" data-reactid=".0.2.0.0.0.2.0">...</a>

When I click on the second one, hash is populated in the location object and I'm being taken to the fragment. When I click on the first one, I'm being taken to \faq, hash is not populated in the location object and I'm not being taken to the fragment. Any idea why is that?

@aszwemin
Copy link
Author

aszwemin commented Oct 9, 2015

Think I found the reason.

if (allowTransition) this.context.history.pushState(this.props.state, this.props.to, this.props.query);

allowTransition is true in my case so the pushState is called, but it doesn't take hash under consideration.

@taion
Copy link
Contributor

taion commented Oct 9, 2015

It's true in both cases, though. Are you sure you're on RC3?

@aszwemin
Copy link
Author

aszwemin commented Oct 9, 2015

Yes, using RC3. Preventing default and doing pushState(this.props.state, this.props.to, this.props.query) seems to make Link not working with hashes.

@mjackson
Copy link
Member

mjackson commented Oct 9, 2015

Good catch, @aszwemin. We really should have a test around this. Are you up for a PR? You can use the existing tests around <Link>'s onClick behavior as a starting point.

@mjackson mjackson added the bug label Oct 9, 2015
@mjackson mjackson changed the title [Question] Using fragments - location doesn't contain hash Fix <Link hash> Oct 9, 2015
@timdorr
Copy link
Member

timdorr commented Oct 9, 2015

Created a failing test here: master...timdorr:test-link-hash

I'll get a fix together shortly.

@aszwemin
Copy link
Author

aszwemin commented Oct 9, 2015

👍

@davis davis mentioned this issue Oct 15, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants