【问题标题】:Ember: willTransition() in route breaks link-to helper active classEmber:路由中的 willTransition() 中断链接到帮助程序活动类
【发布时间】:2018-01-21 06:15:17
【问题描述】:

将此操作添加到我的路线后:

  actions: {
    willTransition() {
      this.refresh();
    }
  }

模板内所有引用嵌套路由的链接都被标记为活动的,即使它们生成的网址具有不同的动态段

我制作了一个 Ember Twiddle to reproduce the bug。它只发生在 willTransition() 动作中,而不是 redirect() 钩子。 (我需要使用 willTransition 来刷新父路由。)

有一件事要提一下:在第一次渲染时,一切都井井有条。当 willTransition 被触发时它会中断。

有什么想法吗? :)

更新

导致问题的原因似乎是 this.refresh() 而不是 willTransition() 操作。

【问题讨论】:

    标签: javascript ember.js handlebarshelper


    【解决方案1】:

    我不确定这是否只是因为你把小提琴弄得很快……但你作为参数传入的模型不应该用引号引起来

    {{link-to 'route.destination' 'Visual representation' model.thing}}
    

    inline vs block // inline 总是令人困惑...如果文本的“值”是定义差异...它可能应该是第一个参数...

    {{#link-to 'route.destination' model.thing}}
      <span>{{model.name}}</span>
    {{/link-to}}
    

    https://ember-twiddle.com/702ab44ba8090a50cfabda353cffc599

    这个稍微复杂的小提琴表明它可以正常工作......我想......让我知道。 :)

    编辑:我看到你对这些段做了什么......并利用了默认值 - 但也有这个错误:/paternt' did not match any routes in your application

    我开始认为这种行为是正常的。它们都处于活动状态,因为您在默认 parent.sibling.index

    我建议你把事情设置成这样,然后看看问题是否仍然存在

    Router.map(function() {
      this.route('parent', function(){
        this.route('child-list' {path: '/'});
        this.route('child-detail', {path: ':thing'});
      })
    });
    

    (我一直在尝试分叉你的小玩意——但它只是重定向到我的小提琴......古怪的东西)

    【讨论】:

    • 感谢您抽出宝贵时间 :)!是的,正如您所注意到的,我并没有尝试传递模型来从中构建动态段。我直接用字符串传递动态段值。 'seg1'、'seg2'、'seg3'..(其中 'seg' == 段)。找不到你提到的其他错误,但我稍微完善了一点;)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    相关资源
    最近更新 更多