如何使用链接定义重新使用的嵌套路由的ember链接? [英] How are ember links to reused nested routes defined using link-to?

查看:98
本文介绍了如何使用链接定义重新使用的嵌套路由的ember链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Router.map (function(){
this.route('post',{path:'/ post /:post_id'},function(){
this.route('edit');
this.route('comments',{resetNamespace:true},function(){
this.route('new');
});
});
这个.route('comments');
});

由于 resetNamespace:true ,路线post.comments不存在。

  {{#link-topost.comments123}}链接{{/ link-to}} 

当尝试使用注释ID链接到新闻时,错误发生了更多的上下文对象,而不是有路由的动态段:

  {{#link-tocomments123}}链接{{/ link-to}} 

第二种情况的例子可以在这里看到: https://ember-twiddle.com/d9f3b5e692573c80e803

解决方案

由于您重置了命名空间,因此您有效地覆盖了 / code>路由与另一个。你正在做一些类似于

  obj ['comments'] = firstRoute; 
obj ['comments'] = secondRoute;

路由名称必须是唯一的,如果您没有重置命名空间,那么它们将是作为路径。如果两条路线都有 / foobar 路径,则Ember将不知道要转移到哪一条路线。



如果您想要的是重新使用其他路线的部件,有办法那个


Using the example route defined below how can a link be defined to /post/123/comments?

Router.map(function() {
  this.route('post', { path: '/post/:post_id' }, function() {
    this.route('edit');
    this.route('comments', { resetNamespace: true }, function() {
      this.route('new');
    });
  });
  this.route('comments');
});

Since resetNamespace: true is set on comments, the route post.comments does not exist. Otherwise the following would work.

{{#link-to "post.comments" "123"}}Link{{/link-to}}

When trying to link to news using the comment id, the error More context objects were passed than there are dynamic segments for the route: comments occurs.

{{#link-to "comments" "123"}}Link{{/link-to}}

An example of the second case can be seen here: https://ember-twiddle.com/d9f3b5e692573c80e803

解决方案

Since you're resetting the namespace, you are effectively overriding one of the comments route with the other. You're doing something akin to

obj['comments'] = firstRoute;
obj['comments'] = secondRoute;

Route names need to be unique, which they would be if you didn't reset the namespace, as well as the path. If two routes have the /foobar path, then Ember won't know which one to transition to.

If what you want is to reuse parts from other routes, there are ways to do that.

这篇关于如何使用链接定义重新使用的嵌套路由的ember链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆