如何清除url中指定参数,并返回url?
文章目录
export function deleteUrlQueryByName(param) {
const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)');
const r =
window.location.search.substr(1).match(reg) ||
window.location.hash
.substring(window.location.hash.search(/\?/) + 1)
.match(reg);
if (r != null) {
return window.location.href.replace(
`${param}=${decodeURIComponent(r[2])}`,
'',
);
}
return window.location.href;
}
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论