feat(v2): open external links in new tab by default (#2780)

Docusaurus is already opinionated about doing this, for example the navbar and
footer do this already.

This changes the Link component to do the same. This includes links in markdown
in the form of `[label](url)`.

You can override this behaviour by passing the target: '_self' prop.
This commit is contained in:
John Knox 2020-05-21 12:34:33 +01:00 committed by GitHub
parent 05c3aa31f4
commit 70c201c24d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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