[英]Dynamic model in LinkTo component in Ember
I am using Ember 3.18, I am facing the below issue.我正在使用 Ember 3.18,我面临以下问题。 Consider the following routes:
考虑以下路线:
Router.map(function() {
this.route('author');
this.route('author' , {path:"/author/:author_id"});
});
Now, in my hbs file, I am trying to transition to the above routes using a single LinkTo.现在,在我的 hbs 文件中,我尝试使用单个 LinkTo 转换到上述路由。 As you can see, only the second route requires model attribute.
如您所见,只有第二条路线需要 model 属性。 In simple terms, I want to combine the below 2 into a single line.
简单来说,我想将以下 2 个组合成一行。
<LinkTo @route="author" />
<LinkTo @route="author" @model="2" />
As you can see, I require the model attribute to be gone in certain cases and availble in certain cases.如您所见,我要求 model 属性在某些情况下消失并在某些情况下可用。
Please help.请帮忙。
I think the easiest way forward is to tweak your routing setup a bit.我认为最简单的方法是稍微调整一下路由设置。 I know you want to combine the routes, but it's hard/confusing, imo, and would be "more standard" to do something more traditional like:
我知道您想合并这些路线,但是很难/令人困惑,imo,并且做一些更传统的事情会“更标准”,例如:
Router.map(function() {
this.route('author', function() {
this.route('view', {path:":author_id"});
});
});
and和
<LinkTo @route="author.index" />
<LinkTo @route="author.view" @model="2" />
author.index
would match /author
and author.view
(with a @model
) would match /author/2
. author.index
将匹配/author
并且author.view
(带有@model
)将匹配/author/2
。
Note that index is an implicit convention of the web, and not needed in the router.js file请注意,索引是 web 的隐式约定,在 router.js 文件中不需要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.