我注意到
value
的 URLSearchParams.has()
参数仅在 Firefox 中受支持:
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/has
示例:
// URL: https://example.com?color=orange
const searchParams = useSearchParams(); // Next.js Hook
const params = new URLSearchParams(searchParams);
// params.has(name, value)
params.has("color", "green") // Firefox correctly returns false; other browsers return true because they only check "color" and not its value.
我正在考虑创建自己的函数,但是已经有一个填充函数可以实现吗?如果是,我该如何使用它(如果有帮助的话我正在使用 Next.js)?
这适用于任何支持 searchParams 的浏览器
const hasValue = (params,name,value) => params.has(name) && params.get(name) === value;