例如,删除url的token参数
删除前:http://xxxxxxxx/#/dynamic?token=4654561654asd4asd&id=03e657722d5056820c5f&cityName=广州市
删除后:http://xxxxxxxx/#/dynamic?id=03e657722d5056820c5f&cityName=广州市
/*** 删除URL中指定search参数,会将参数值一起删除* @param {string} url 地址字符串* @param {array} param 要删除的参数key数组,如['name','age']* @return {string} 返回新URL字符串*/ridUrlParam(url, params) {for (var index = 0; index < params.length; index++) {var item = params[index];//必须加=号,避免参数值中包含item字符串var fromIndex = url.indexOf(item + "="); if (fromIndex !== -1) {// 通过url特殊符号,计算出=号后面的的字符数,用于生成replace正则var startIndex = url.indexOf("=", fromIndex);var endIndex = url.indexOf("&", fromIndex);var hashIndex = url.indexOf("#", fromIndex);var reg = "";if (endIndex !== -1) {// 后面还有search参数的情况var num = endIndex - startIndex;reg = new RegExp(item + "=.{" + num + "}");url = url.replace(reg, "");} else if (hashIndex !== -1) {// 有hash参数的情况var num = hashIndex - startIndex - 1;reg = new RegExp("&?" + item + "=.{" + num + "}");url = url.replace(reg, "");} else {// search参数在最后或只有一个参数的情况reg = new RegExp("&?" + item + "=.+");url = url.replace(reg, "");}}}var noSearchParam = url.indexOf("=");if (noSearchParam === -1) {// 如果已经没有参数,删除?号url = url.replace(/\?/, ""); }return url;}