gatsby-starter-hello-friend icon indicating copy to clipboard operation
gatsby-starter-hello-friend copied to clipboard

Main menu doesn't support external links

Open oscmedgon opened this issue 5 years ago • 0 comments

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>
      )
    }
  })
}

oscmedgon avatar Jul 11 '19 11:07 oscmedgon