我正在使用query-string(version 5),想知道是否可以使用它删除查询字符串吗?
results?condition=Used
我想从网址中完全删除condition
。
如果没有其他替代方法?
答案 0 :(得分:0)
要处理url,我更喜欢使用url package。对于你来说,我会做
const url = require('url');
const targetUrl = 'results?condition=Used&year=2010';
const parsedUrl = url.parse(targetUrl, true);
delete parsedUrl.search; // need to delete it so we can construct new query
delete parsedUrl.query.condition; // delete "condition"
console.log(url.format(parsedUrl)); // results?year=2010