Javascript 链路在子路由中设置为活动
我注意到,当我在路径Javascript 链路在子路由中设置为活动,javascript,ember.js,Javascript,Ember.js,我注意到,当我在路径forums.archives中时,使用{{{{#link to'forums}}}forums{{/link to}}定义的链接被设置为活动类 Router.map(function () { this.route('forums', function () { this.route('new'); this.route('archives'); }); }); 导航: {{#link-to 'forums'}}Forums
forums.archives
中时,使用{{{{#link to'forums}}}forums{{/link to}}
定义的链接被设置为活动类
Router.map(function () {
this.route('forums', function () {
this.route('new');
this.route('archives');
});
});
导航:
{{#link-to 'forums'}}Forums{{/link-to}}
{{#link-to 'forums.archives'}}Forum archives{{/link-to}}
他们俩都上了活跃的课
如果链接上的活动类与url不100%匹配,是否有方法删除该类
谢谢所以您有一个嵌套的
路由
,老实说,我不知道它是如何工作的。Ember团队的说法是,它的工作原理与嵌套资源相同,但有许多微妙之处(如这一点)没有真正意义。所以这里是我要做的(这可能不是你应该做的)。假设您的导航位于应用程序模板中:
App.ApplicationController = Ember.ObjectController.extend({
isForumsActive: function() {
return (this.get('currentRouteName') === 'forums');
}.property('currentRouteName')
});
{{#link-to 'forums' active=isForumsActive}}Forums{{/link-to}}
{{#link-to 'forums.archives'}}Forum archives{{/link-to}}
然后,在模板中:
App.ApplicationController = Ember.ObjectController.extend({
isForumsActive: function() {
return (this.get('currentRouteName') === 'forums');
}.property('currentRouteName')
});
{{#link-to 'forums' active=isForumsActive}}Forums{{/link-to}}
{{#link-to 'forums.archives'}}Forum archives{{/link-to}}
您可能还希望更改路线的方式,以便嵌套更干净:
Router.map(function () {
this.resource('forums', function () {
// this.route('index'); -- implicitly defined
this.route('new');
this.route('archives');
});
});
然后你的链接可以指向论坛。索引 你能发布你的路由器地图吗(至少是论坛的部分)?我更新了这个问题。