【问题标题】:Dynamic segments for nested ember routes not working嵌套 ember 路由的动态段不起作用
【发布时间】:2015-10-22 04:02:41
【问题描述】:

我有一个嵌套的路由结构:

 //router.js

  this.route('maps', { path: '/maps' }, function () {
    this.route('show', { path: '/:id' }, function () {
      this.route('display', { path: '/display' }),
      this.route('layers', function () {
        this.route('create')
      })
    });
  });

我的理解是,我应该有一条路线 maps.show.display,它应该采用单个动态段,例如 maps/1/display

但是,当我去过渡或链接到这个即:

//maps route

afterModel: function (resolvedModel) {
 var newestFlight = resolvedModel.content[0];
 var newestMap = newestFlight.get('map');
 this.transitionTo('maps.show.display', newestMap);
}

{{#link-to 'maps.show.display' id}}show map{{/link-to}}

我得到一个错误:

 Error while processing route: maps.index More context objects were passed than there are dynamic segments for the route: maps.show.index

更奇怪的是,这条路由接受了相同的动态段,而它只是 maps/display,所以我不明白为什么嵌套它会进一步破坏它。

任何关于我做错了什么的想法将不胜感激

编辑:有趣的是,this awesome tool

似乎也同意,如果您在此处发布我的路线,我应该在此处有一个动态段

【问题讨论】:

    标签: ember.js ember-cli


    【解决方案1】:

    对我来说很好用:http://emberjs.jsbin.com/rofowuneni/1/edit?html,css,js,output

    顺便说一句,我认为:

    this.route('display', { path: '/display' });
    this.route('layers', function () {
      this.route('create')
    });
    

    应该是(没关系):

    this.route('display', { path: '/display' });
    this.route('layers', function () {
      this.route('create');
    });
    

    你的 ember 版本是什么?

    【讨论】:

    • 当前运行 1.13.0 可能是我调用它的地方还是应该不重要?可能是在 mapsRoute 中我的上下文不正确还是什么?如果它有所作为,我在尝试移动到 pod 结构时遇到了这个问题
    • @Andrew 如果直接访问目标 URL 会发生什么?
    • uhhh ...让我们忘记这一切。我在 router.js 的底部隐藏了一个无效的路由定义,它用废话覆盖了上面显示的路由。非常感谢你。你最后的评论帮助我弄清楚了。由您决定,但如果您想将此添加为答案,我会接受它
    • 除了分号有区别吗?
    • 我想不到。我只是认为您的路线可能已损坏,而不是链接可能。很高兴你想出来了。 :)
    猜你喜欢
    • 2014-07-05
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2013-01-09
    • 1970-01-01
    • 2016-07-28
    • 2017-10-05
    相关资源
    最近更新 更多