window.history.pushState 删除“?”来自查询字符串

时间:2021-03-29 15:23:51

标签: javascript url-parameters pushstate

我有一个页面已经使用了 get 参数

https://example.com/?name=Dimitar

现在我有一个 onClick 函数

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);

function updateURL(skill, value) {
    urlParams.set(skill, value)
    window.history.pushState({}, '', urlParams);
}

我想用附加参数更新查询字符串。它确实做到了,但它去掉了“?”从我的查询字符串和我的 URL 变为 https://example.com/name=Dimitar&newparam=1 页面转到

“/”应用程序中的服务器错误。 从客户端 (&) 检测到潜在危险的 Request.Path 值。

0 个答案:

没有答案