常见问题汇总
解决控制台对a
标签href
属性使用javascript:;
导致的warning
- 2020.05.15
问题描述
URLs starting with javascript: are a dangerous attack surface because it’s easy to accidentally include unsanitized output in a tag like
<a href>
and create a security hole.
In React 16.9, this pattern continues to work, but it will log a warning. If you use javascript: URLs for logic, try to use React event handlers instead.
解决方案
href属性
值使用#!
// before
<a href="javascript:;" onClick={onClick}>我是一个超链接</a>
// after
<a href="#!" onClick={onClick}>我是一个超链接</a>