github.hscsec.cn/hashicorp/consul@v1.4.5/ui-v2/app/initializers/route-urldecode-params.js (about) 1 import Route from '@ember/routing/route'; 2 import { routes } from 'consul-ui/router'; 3 import wildcard from 'consul-ui/utils/routing/wildcard'; 4 const isWildcard = wildcard(routes); 5 /** 6 * This initializer adds urldecoding to the `params` passed into 7 * ember `model` hooks, plus of course anywhere else where `paramsFor` 8 * is used. This means the entire ember app is now changed so that all 9 * paramsFor calls returns urldecoded params instead of raw ones 10 */ 11 Route.reopen({ 12 paramsFor: function() { 13 const params = this._super(...arguments); 14 if (isWildcard(this.routeName)) { 15 return Object.keys(params).reduce(function(prev, item) { 16 if (typeof params[item] !== 'undefined') { 17 prev[item] = decodeURIComponent(params[item]); 18 } else { 19 prev[item] = params[item]; 20 } 21 return prev; 22 }, {}); 23 } else { 24 return params; 25 } 26 }, 27 }); 28 export function initialize() {} 29 30 export default { 31 initialize, 32 };