问题
I have a nav bar that has special CSS that shows up when a link has the "active" class on it. It looks something like this:
<ul>
<li>{{link-to "routeName"}}<i class="icon-up"></i>{{/link-to}}</li>
{{!-- more list items like the previous one... --}}
</ul>
However, when I click on the link with "routeName", a rather expensive query is made that may be slow at times. I have a LoadingRoute set up with a loading view that consists of a simple spinner, but it seems like the link does not receive the "active" class until the route's promise is resolved. Is there a Handlebars-friendly way to tell link-to to immediately set the "active" class when it is clicked?
回答1:
The reason for this is that the URL does not get updated until the end of a transition. Thanks to the peeps in the Ember IRC and Machty, this is an issue that has been resolved and will be in the next beta cycle.
- The fix: https://github.com/emberjs/ember.js/pull/4122
- The beta cycle "go" progress: https://github.com/emberjs/ember.js/issues/4052
来源:https://stackoverflow.com/questions/21420098/ember-link-to-set-active-class-immediately