fix(links): unify linking to pages internal/external

This commit is contained in:
Mrugesh Mohapatra
2019-02-18 17:13:00 +05:30
committed by Stuart Taylor
parent f28cee5a4d
commit f61efb225f
8 changed files with 135 additions and 157 deletions

View File

@@ -0,0 +1,20 @@
import React from 'react';
import { Link as GatsbyLink } from 'gatsby';
const Link = ({ children, to, external, ...other }) => {
if (!external && (/^\/(?!\/)/).test(to)) {
return (
<GatsbyLink to={to} {...other}>
{children}
</GatsbyLink>
);
}
return (
<a href={to} {...other} rel='noopener noreferrer' target='_blank'>
{children}
</a>
);
};
export default Link;