refactor(v2): make external links more secure (#2783)

This commit is contained in:
Alexey Pyltsyn 2020-05-22 06:18:27 +03:00 committed by GitHub
parent 70c201c24d
commit 7448501c7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View file

@ -85,8 +85,9 @@ function Link({isNavLink, ...props}: Props) {
return !targetLink || !isInternal || targetLink.startsWith('#') ? ( return !targetLink || !isInternal || targetLink.startsWith('#') ? (
// eslint-disable-next-line jsx-a11y/anchor-has-content // eslint-disable-next-line jsx-a11y/anchor-has-content
<a <a
{...(isInternal ? props : {target: '_blank', ...props})}
href={targetLink} href={targetLink}
{...(!isInternal && {target: '_blank', rel: 'noopener noreferrer'})}
{...props}
/> />
) : ( ) : (
<LinkComponent <LinkComponent

View file

@ -73,7 +73,7 @@ const Page = () => (
Check out my <Link to="/blog">blog</Link>! Check out my <Link to="/blog">blog</Link>!
</p> </p>
<p> <p>
{/* Note that external links still use `a` tags. */} {/* Note that external links still use `a` tags, but automatically opens in new tab. */}
Follow me on <a href="https://twitter.com/docusaurus">Twitter</a>! Follow me on <a href="https://twitter.com/docusaurus">Twitter</a>!
</p> </p>
</div> </div>