【问题标题】:Link to a child route but have active class on parent route链接到子路线,但在父路线上有活动课程
【发布时间】:2015-08-08 16:12:00
【问题描述】:

我有一个导航栏项目

{{#link-to 'customer'}}

点击后我希望它路由到customer.details 路由。我目前可以通过将customer 路由重定向到customer.details 来实现这一点。但是,当在customer.details 路由内时,如果我单击导航中的链接,它会转换到customer 路由,而不是发送到customer.detailsredirectactivate 或模型之前/之后的路径函数都不会在过渡到路径链时触发。

另一个选项

{{#link-to 'customer.details'}}

这意味着任何其他 customer.routename 都不会继承活动类。

我错过了什么吗?谢谢。

【问题讨论】:

    标签: ember.js ember-cli


    【解决方案1】:

    我的链接是在 Ember 2.0 上使用上述来自 Goobi 的解决方案进行的。

    在我的路由器中,我有:

    this.route('event', {path: '/:eventShortName'}, function(){
        this.route('index', {path: '/'});
        this.route('new-article', {path: 'new-article'});
        this.route('page', {path: ':articleTitle'}, function(){
          this.route('data', {path: ':dataId'});
        });
      });
    

    每当我访问 event.page.data 时,导航栏中的所有链接都会处于活动状态。

    修复前:

    {{#link-to 'event.page' article.articleURL class="nav-dynamic hidden-xs" tagName="li" href=false}}
       {{#link-to 'event.page' article.articleURL }}
          {{article.articleTitle}}
       {{/link-to}}
    {{/link-to}}
    

    修复后:

    {{#link-to 'event.page.index' article.articleURL class="nav-dynamic hidden-xs" tagName="li" href=false}}
       {{#link-to 'event.page.index' article.articleURL }}
          {{article.articleTitle}}
       {{/link-to}}
    {{/link-to}}
    

    功能保持不变,现在访问数据 url 时没有链接处于活动状态。

    【讨论】:

      【解决方案2】:

      所以编辑 KerrickLong 帮我解决了这个问题:


      尝试在 customer.index 上实时重定向到 customer.details 路线而不是直接在客户路线上。

      完美运行!

      【讨论】:

      • 非常感谢您如何执行此操作的一些示例代码 :)
      猜你喜欢
      • 2020-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      • 2015-07-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多