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' role='menu'
> >
<li className='nav-news' role='menuitem'> <li className='nav-news' role='menuitem'>
<Link external={true} to='/news'> <Link external={true} sameTab={true} to='/news'>
/news /news
</Link> </Link>
</li> </li>
<li className='nav-forum' role='menuitem'> <li className='nav-forum' role='menuitem'>
<Link external={true} to='/forum'> <Link external={true} sameTab={true} to='/forum'>
/forum /forum
</Link> </Link>
</li> </li>

View File

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