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

Inability to render a linkTo with a target #19141

Closed
amk221 opened this issue Sep 18, 2020 · 3 comments
Closed

Inability to render a linkTo with a target #19141

amk221 opened this issue Sep 18, 2020 · 3 comments

Comments

@amk221
Copy link

amk221 commented Sep 18, 2020

With the LinkTo component, it's not possible to render a link that points to a target on the destination route.

e.g. <a href="/my-route#foo"></a>

I did ask around in discord about this before raising an issue. But I am still unsure whether Ember is concerned about this, or if it's just up to me to sort in my application.

@chancancode
Copy link
Member

What specifically do you mean by target here? Do you mean the #foo anchor? If so, then yeah it's a general limitation of Ember.

More specifically are you referring to:

  1. The inability to pass an "anchor" argument to the <LinkTo> component to generate a link that looks like this, and/or
  2. Even if it's possible to generate a link like this, it still doesn't do anything – clicking on it doesn't scroll to the anchor like it would on a server-rendered page?

1 is relatively easy to add, though I'm not sure we want to add more features to <LinkTo> at this point, as the general strategy is to make <a href="/..."> Just Work™ and provide helpers so you can do things like <a href="{{href-to ...}}">. At which point, it still is an open question of whether the href-to (or whatever helper API we land on) should accept an anchor argument or not, but in that world, even if it didn't, it would be relatively easy for you to add it via string concatenation yourself.

2 is has more open questions around what exactly it means to make it "work" in a single page app – does it mean calling scrollIntoView on the element, or does it just mean providing a hook in the router for your app to handle this post-transition and post-rendering, etc? It'll probably require more brainstorming and ultimately an RFC.

In the meantime, yeah, it's pretty common for applications to have to write custom code to handle this today.

@amk221
Copy link
Author

amk221 commented Sep 22, 2020

What specifically do you mean by target here?

I said "target", but it can be referred to as hash, anchor or target in different circumstances. But you assumed the right thing.

I expected LinkTo to route to the @route and then 'jump' to the anchor as per native browser behaviour, as if you had used an <a>.

But, as you say - not doing so, allows developers to chose their own behaviour, so that's fine.

Thanks for clarifying.

@amk221 amk221 closed this as completed Sep 22, 2020
@amk221
Copy link
Author

amk221 commented Apr 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants