Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Ember.js中选择路线参数?_Ember.js_Ember Cli_Ember Router - Fatal编程技术网

如何在Ember.js中选择路线参数?

如何在Ember.js中选择路线参数?,ember.js,ember-cli,ember-router,Ember.js,Ember Cli,Ember Router,在Ember.js中,给定以下路线: this.route('chefs', { path: ":country/chefs"}); this.route('recipes', { path: ":country/recipes"}); 我需要在链接到组件中放置位置参数,如: {{#link-to 'chefs' 'mx'}}Mexico Chefs{{/link-to}} 如何避免在所有组件链接中指定某些参数 我认为“chefs”路由可以使用来自服务的默认参数。但是怎么做呢?还有其他想法吗

在Ember.js中,给定以下路线:

this.route('chefs', { path: ":country/chefs"});
this.route('recipes', { path: ":country/recipes"});
我需要在链接到组件中放置位置参数,如:

{{#link-to 'chefs' 'mx'}}Mexico Chefs{{/link-to}}
如何避免在所有组件链接中指定某些参数

我认为“chefs”路由可以使用来自服务的默认参数。但是怎么做呢?还有其他想法吗

这里有一个小把戏:

编辑

这种需求的另一个例子是使用嵌套管线时。想象一个菜单组件,其中包含指向“厨师”和“食谱”的链接。当放置在名为“country”的父路由中时,比如“/ca”,链接不需要参数

{{#link-to 'chefs'}}Chefs{{/link-to}}
{{#link-to 'recipes'}}Recipes{{/link-to}}
它们将在“/ca/chefs”和“/ca/recipes”之间导航。但是,当这个假设的菜单放在根级路由上时,比如说“/login”,菜单将出错“断言失败:您试图定义一个
{{link to“chefs”}
,但没有传递生成其动态段所需的参数…”

我想给路由一个默认的“国家”参数,当一个没有通过链接


我看到的另一种选择似乎不太优雅,就是创建一个服务并在每个链接中注入“country”参数。

从URL的角度考虑。开放式厨师URL是什么样子的?{{{#链接到“厨师”}厨师{{/link到}}加拿大游客可以访问/ca/chefs,墨西哥游客可以访问/mx/chefs