fix: open universal nav links on the same tab (#38273)

This commit is contained in:
Ahmad Abdolsaheb
2020-02-26 22:09:56 +03:00
committed by GitHub
parent 402ccb36f1
commit 2c3de17c74
2 changed files with 10 additions and 3 deletions

View File

@ -15,12 +15,12 @@ function NavLinks({ displayMenu }) {
role='menu'
>
<li className='nav-news' role='menuitem'>
<Link external={true} to='/news'>
<Link external={true} sameTab={true} to='/news'>
/news
</Link>
</li>
<li className='nav-forum' role='menuitem'>
<Link external={true} to='/forum'>
<Link external={true} sameTab={true} to='/forum'>
/forum
</Link>
</li>

View File

@ -5,16 +5,23 @@ import { Link as GatsbyLink } from 'gatsby';
const propTypes = {
children: PropTypes.any,
external: PropTypes.bool,
sameTab: PropTypes.bool,
to: PropTypes.string.isRequired
};
const Link = ({ children, to, external, ...other }) => {
const Link = ({ children, to, external, sameTab, ...other }) => {
if (!external && /^\/(?!\/)/.test(to)) {
return (
<GatsbyLink to={to} {...other}>
{children}
</GatsbyLink>
);
} else if (sameTab && external) {
return (
<a href={to} {...other}>
{children}
</a>
);
}
return (