Skip to content

Commit

Permalink
feat(v2): open external links in new tab by default (#2780)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jknoxville authored May 21, 2020
1 parent 05c3aa3 commit 70c201c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/docusaurus/src/client/exports/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 70c201c

Please sign in to comment.