如何在ember中的url中显示默认查询参数值?

ahn*_*cad 1 ember.js ember-query-params

如果查询参数值是默认值,则Ember不会在URL中显示查询参数。但我想展示一下。是否可以将这种行为更改为显示而不是隐藏?

App.IndexController = Ember.ArrayController.extend({
  queryParams: ['type'],
  type: "horror"  // the default value, won't appear in URL or params
})
Run Code Online (Sandbox Code Playgroud)

GJK*_*GJK 5

默认值和序列化在本指南部分中进行了说明。不幸的是,它没有提供包括默认值的方法,而且我不确定是否有开箱即用的方法。

但是,有一个小技巧。null设置查询参数时,不要在路由中使用默认值,而应在路由中使用并设置默认值。从您的角度来看,这使Ember认为它不是默认值。

App.IndexRoute = Ember.Route.extend({
    resetController: function(controller) {
        controller.set('type', 'horror');
        return this._super.apply(this, arguments);
    }
});

App.IndexController = Ember.ArrayController.extend({
    queryParams: ['type'],
    type: null
});
Run Code Online (Sandbox Code Playgroud)