html - 这个无效的正则表达式标志错误是什么?
问题描述
我有条件地在我的 React 应用程序中渲染一个 div。这个...
if (props.trades.length > 0)
return <div class="header">Your trades:</div>
else
return <div class="header">You haven't made any trades.</div>
有效,但我想像这样在第二个选项中包含一个链接
if (props.trades.length > 0)
return <div class="header">Your trades:</div>
else
return <div class="header">You haven't made any trades. Click <a to={{/page}}>here</a> to make a trade.</div>
但是我在关闭标签时收到此错误:“解析错误:无效的正则表达式标志”。
为什么是这样?
解决方案
发生这种情况是因为您应该使用to
这种方式:
注意:如果您使用的是 html a tag
,您可能希望更改to
为href
<a to="/page">here</a>
// or
const to = "/page"
...
<a to={to}>here</a>
推荐阅读
- laravel - 想要使用 vuejs 显示 laravel 验证消息
- python - 创建集群时出现错误 pandas._libs.hashtable.Int64HashTable.get_item
- java - 为 IntelliJ 中的所有参数添加 @NotNull 注释
- android - Android 10 MediaStore API 更改
- c++ - 如何获取在 CStaticCtrl 上播放的 libVLC 媒体的点击事件
- javascript - 从 facebook-passport 回调重定向后缺少 cookie
- javascript - 在模态中获取输入类型=日期的值
- csv - Spark:如何定义模式以读取具有不同列数的 csv 文件?
- java - 通过参数泛型方法查找 JPA 存储库
- android - 应用程序作为“后台进程”打开。有可能反应原生吗?