Ember:相同的路线,不同的路径
Ember: same route, different paths
我希望以 3 种不同的方式调用路由:
this.route('issue', {path: '/foo/:param1'});
this.route('issue', {path: '/foo/:param1/:param2'});
this.route('issue', {path: '/foo/:param1/:param2/:param3'});
但是当我尝试 link-例如使用:
{{#link-to 'issue' issue.id issue.tag}}{{/link-to}}
我收到这个错误:
Error: You didn't provide enough string/numeric parameters
to satisfy all of the dynamic segments for route issue
我尝试更改路由器中的调用顺序,但没有成功。我想我对如何检测路线缺乏一些理解。有什么想法吗?
在这里使用查询参数可能更有意义。所以在路由器中只定义一条路由:
this.route('issue', {path: '/foo/param1'});
然后在控制器中为 param2 和 param3 定义查询参数:
export default Controller.extend({
queryParams: ['param2', 'param3'],
param2: null,
param3: null
});
然后您可以将它们用于 filter your data。我假设 param1 定义了实际模型,但 2 和 3 用于过滤,但您可以通过将所有三个移动到 queryParams 来使它们全部可选。
您可以在 link-to helper 中设置任意数量(或 none)的查询参数:
{{#link-to "posts" (query-params direction="asc")}}Sort{{/link-to}}
这里有一些关于查询参数的文档,在我看来这是最酷的 Ember 功能之一:http://guides.emberjs.com/v2.2.0/routing/query-params
我希望以 3 种不同的方式调用路由:
this.route('issue', {path: '/foo/:param1'});
this.route('issue', {path: '/foo/:param1/:param2'});
this.route('issue', {path: '/foo/:param1/:param2/:param3'});
但是当我尝试 link-例如使用:
{{#link-to 'issue' issue.id issue.tag}}{{/link-to}}
我收到这个错误:
Error: You didn't provide enough string/numeric parameters
to satisfy all of the dynamic segments for route issue
我尝试更改路由器中的调用顺序,但没有成功。我想我对如何检测路线缺乏一些理解。有什么想法吗?
在这里使用查询参数可能更有意义。所以在路由器中只定义一条路由:
this.route('issue', {path: '/foo/param1'});
然后在控制器中为 param2 和 param3 定义查询参数:
export default Controller.extend({
queryParams: ['param2', 'param3'],
param2: null,
param3: null
});
然后您可以将它们用于 filter your data。我假设 param1 定义了实际模型,但 2 和 3 用于过滤,但您可以通过将所有三个移动到 queryParams 来使它们全部可选。
您可以在 link-to helper 中设置任意数量(或 none)的查询参数:
{{#link-to "posts" (query-params direction="asc")}}Sort{{/link-to}}
这里有一些关于查询参数的文档,在我看来这是最酷的 Ember 功能之一:http://guides.emberjs.com/v2.2.0/routing/query-params