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

Asynchronous routes cause wonky link-to behaviour when nested #10366

Closed
markprzepiora opened this issue Feb 6, 2015 · 6 comments
Closed

Asynchronous routes cause wonky link-to behaviour when nested #10366

markprzepiora opened this issue Feb 6, 2015 · 6 comments
Milestone

Comments

@markprzepiora
Copy link

A pattern I previously used to mark an outer HTML tag as active or not (e.g. an <li> tag) rather than the link itself, is something like this:

  {{#link-to "foo" tagName="li"}}
    {{#link-to "foo"}}
      foo
    {{/link-to}}
  {{/link-to}}

This has worked perfectly fine going back to I think even before 1.0. But this is now broken in 1.11 canary (still works fine in the current 1.10 beta). When the foo route is asynchronous, clicking on it transitions the page perfectly fine, but the active classes are not updated.

The solution is to add bubbles=false to the inner link-tos, like so:

  {{#link-to "foo" tagName="li"}}
    {{#link-to "foo" bubbles=false}}
      foo
    {{/link-to}}
  {{/link-to}}

This is a regression, but is it an expected one? I'm sure that changing the tagName of a link-to isn't exactly an intended API, but I know this is a pattern that's used in the wild, so I just wanted to bring it to your attention.

It should be noted that synchronous transitions to not exhibit this problem.

JSBin here: http://emberjs.jsbin.com/jahuya/5

@rlivsey
Copy link
Contributor

rlivsey commented Feb 6, 2015

As an aside, ideally there'd be a helper for detecting if a route is active which could be used in a sub-expression here so you wouldn't have to nest link-to's anymore.

Something like:

<li class="{{if (is-current-route "foo") "active"}}>
  {{#link-to "foo"}}foo{{/link-to}}
</li>

It might be easier to implement that helper than fix the link-to regression & make nested link-to's a thing of the past!

@rwjblue
Copy link
Member

rwjblue commented Feb 6, 2015

I use the following technique usually: http://emberjs.jsbin.com/rwjblue/285/edit?html,js,output

@mixonic
Copy link
Member

mixonic commented Mar 18, 2015

@bantic and I explored and have additional explanation for what is going wrong:

@alexspeller
Copy link
Contributor

I made an addon with a component for this: https://github.com/alexspeller/ember-cli-active-link-wrapper

@Samsinite
Copy link

👍 on the sub-exp idea, that would work great. Could it be used like so with the class name bindings syntax?

<li class="(is-current-route "foo"):active:">{{#link-to "foo"}}foo{{/link-to}}</li>

machty added a commit to tildeio/router.js that referenced this issue Mar 26, 2015
Transitioning to a route that you're already
transitioning to should just return you that
currently active transition. 

Fixes root cause of emberjs/ember.js#10366
@rwjblue
Copy link
Member

rwjblue commented Mar 26, 2015

Fixed by #10726.

@rwjblue rwjblue closed this as completed Mar 26, 2015
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

6 participants