gatsby-starter-hello-friend
gatsby-starter-hello-friend copied to clipboard
Main menu doesn't support external links
I did a small change to support it in my case, but I want to understand why is not supported
const MainMenu = ({ mainMenu, mainMenuItems, isMobileMenu }) => {
const menu = mainMenu.slice(0)
!isMobileMenu && menu.splice(mainMenuItems)
return menu.map((menuItem, index) => {
const urlRegex = /^(https?:\/\/)?([\da-z\.-]+\.[a-z\.]{2,6}|[\d\.]+)([\/:?=&#]{1}[\da-z\.-]+)*[\/\?]?$/im
const isAbsoluteUrl = menuItem.path.match(urlRegex);
if (isAbsoluteUrl) {
return (
<li key={index}>
<a href={menuItem.path} target='_top'>{menuItem.title}</a>
</li>
)
} else {
return (
<li key={index}>
<Link to={menuItem.path}>{menuItem.title}</Link>
</li>
)
}
})
}