You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置ESLint的no-restricted-properties规则仅禁用window.location.href

配置ESLint规则禁止使用window.location.href

你当前的no-restricted-properties配置直接禁用了window.location整个对象,导致所有子属性都被限制。要只禁用href属性,只需调整配置的对象层级,精准定位到window.location.href:

"no-restricted-properties": ["error", {
  "object": "window.location",
  "property": "href"
}]

这个配置只会拦截对window.location.href的访问或赋值操作,window.location的其他属性(比如pathname、search、hash等)依然可以正常使用。

内容的提问来源于stack exchange,提问作者Tom Fridental

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 09:05:31