Ember nested routes and it's active class
Ember adds automagically a css class active
to all link-to
elements under the current route.
So let's say you have this in your router:
// app/router.js
Router.map(function() {
this.route('blog', function() {
this.route('post', { path: ':slug' });
});
});
If you access a page like http://localhost:4200/blog/last-post
, all the following links will have the active
css class.
{{#link-to 'blog'}}Blog{{/link-to}}
{{#link-to 'blog' post}}{{post.name}}{{/link-to}}
<a id="ember661" href="/blog" class="ember-view active">Blog</a>
<a id="ember663" href="/blog/last-post" class="ember-view active">Last Post</a>
So far so good, but now, if by any reason you just want either child link or parent link with the active
class you can change the parent link-to
to use .index
.
{{#link-to 'blog.index'}}Blog{{/link-to}}
So both blog
and blog.index
links to the same url, but they act differently with active
class.