fix(links): unify linking to pages internal/external
This commit is contained in:
committed by
Stuart Taylor
parent
f28cee5a4d
commit
f61efb225f
20
client/src/components/helpers/Link.js
Normal file
20
client/src/components/helpers/Link.js
Normal 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;
|
Reference in New Issue
Block a user