a 标签里写 javascript: void(0) 或在其他
- If you’re just using <a> for the link styling, consider using a <button> and styling it as a link instead.
- If you still must use <a> for some reason, a workaround is to give it href=”#” onClick={e => e.preventDefault()} .This is not great, so prefer option 1 if you can.
- If you absolutely insist on using a javascript: URL, set it yourself in a ref: <a ref={node => node && node.setAttribute(‘href’, ‘…’)} >. This works for the bookmarklet case.
- If you have hundreds of links like this, as the original post says, one possible solution is to codemod every <a> to <Mylink> and implement either of the above solutions in Mylink. This blog post has an example of something similar.