Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 如何在ember js中仅为确切路线而不是父路线添加活动类?_Ember.js_Ember Cli - Fatal编程技术网

Ember.js 如何在ember js中仅为确切路线而不是父路线添加活动类?

Ember.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

我有两条这样嵌套的路线

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>{{/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,尽管我认为这会掩盖这样一个事实,即在这种情况下可能不应该嵌套路由。