Ember.js 如何在ember js中仅为确切路线而不是父路线添加活动类?
我有两条这样嵌套的路线 router.jsEmber.js 如何在ember js中仅为确切路线而不是父路线添加活动类?,ember.js,ember-cli,Ember.js,Ember Cli,我有两条这样嵌套的路线 router.js this.route('profile', function() { this.route('edit'); }); {{#link-to 'profile' tagName="li"}}<a href>View Profile</a>{{/link-to}} {{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/lin
this.route('profile', function() {
this.route('edit');
});
{{#link-to 'profile' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
{{#link-to 'profile.index' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
还有一些导航条链接,用于这些路线
navbar.hbs
this.route('profile', function() {
this.route('edit');
});
{{#link-to 'profile' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
{{#link-to 'profile.index' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
{{{#链接到'profile'标记名=“li”}{{{/link到}
{{{#链接到'profile.edit'tagName=“li”}{{{/link到}}
指向helper的链接将active
类添加到此处的li
标记中。因此,当我在profile
route中时,第一个链接有active
类,当我在profile.edit
route中时,两个链接都有active
类。(显然是因为访问profile.edit
时,两条路由都被激活。)
在子路由中,如何避免父路由链接以获得活动的
类
基本上,我不希望第一个链接(到profile
)在profile.edit
route
我刚刚将链接更改为profile
,并将其显式设置为profile.index
navbar.hbs
this.route('profile', function() {
this.route('edit');
});
{{#link-to 'profile' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
{{#link-to 'profile.index' tagName="li"}}<a href>View Profile</a>{{/link-to}}
{{#link-to 'profile.edit' tagName="li"}}<a href>Edit Profile</a>{{/link-to}}
{{{#链接到'profile.index'标记名=“li”}{{{/link到}
{{{#链接到'profile.edit'tagName=“li”}{{{/link到}}
这样,当在profile.edit
route中时,第一个链接不会得到active
类。您可以在
时使用current,尽管我认为这会掩盖这样一个事实,即在这种情况下可能不应该嵌套路由。