如何以正确的方式创建路线?
How to create route in right way?
我需要创建 2 条路线
/users/philosophy
/topic/philosophy
/users/
上有一个类别列表,topic
上有一个类别列表。在 /users/philosophy
上有按类别分类的用户列表和相同的主题。类别相同。所以我创建了路由器:
this.resource('categories', { path: '/:section' }, function(){
this.resource('category', {path: '/:url'});
});
并且有效。
但现在我想为用户列表添加过滤器 /users/philosophy/top
。我试着这样做:
this.resource('categories', { path: '/:section' }, function(){
this.resource('category', {path: '/:url/:filter'});
});
但是如果从 url 中删除段 top
,它会抛出错误,所以 filter
参数变得必要。
如何使 filter
参数变得不必要?或者请另一种方式构建路由器。
您似乎在谈论 ember query params。
App.CategoriesCategory = Ember.Controller.extend({
queryParams: ['filter'],
filter: '' /* default value */
});
并使用 filter
参数将用户转移到此路线,使用以下帮助程序
{{#link-to 'categories.category' url (query-params filter="top")}}Show top{{/link-to}}
如果您不想使用该参数,则跳过查询参数。
我需要创建 2 条路线
/users/philosophy
/topic/philosophy
/users/
上有一个类别列表,topic
上有一个类别列表。在 /users/philosophy
上有按类别分类的用户列表和相同的主题。类别相同。所以我创建了路由器:
this.resource('categories', { path: '/:section' }, function(){
this.resource('category', {path: '/:url'});
});
并且有效。
但现在我想为用户列表添加过滤器 /users/philosophy/top
。我试着这样做:
this.resource('categories', { path: '/:section' }, function(){
this.resource('category', {path: '/:url/:filter'});
});
但是如果从 url 中删除段 top
,它会抛出错误,所以 filter
参数变得必要。
如何使 filter
参数变得不必要?或者请另一种方式构建路由器。
您似乎在谈论 ember query params。
App.CategoriesCategory = Ember.Controller.extend({
queryParams: ['filter'],
filter: '' /* default value */
});
并使用 filter
参数将用户转移到此路线,使用以下帮助程序
{{#link-to 'categories.category' url (query-params filter="top")}}Show top{{/link-to}}
如果您不想使用该参数,则跳过查询参数。