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

React报错Unexpected template string expression no-template-curly-in-string 求助

解决React中"Unexpected template string expression no-template-curly-in-string"报错

你的代码报错原因是模板字符串使用了单引号包裹,ESLint的no-template-curly-in-string规则会禁止在普通字符串里出现${}语法——只有用反引号`包裹的模板字符串,才能解析${props.id}这种变量插入逻辑。

修正后的代码:

<Link to={`/product/${props.id}`}><button>Product Details</button></Link>

如果视频里的代码能正常运行,大概率是视频中用了反引号你没留意,或者视频的开发环境没有启用这个ESLint规则。替换成反引号后,既能正确生成带id的路径,也能消除报错。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 23:52:02